1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-18 11:41:17 +02:00

Avoid unnecessary exif_read_data calls (#1371)

EXIF data extraction makes only sense for JPEG and TIFF format. This
patch checks the format and calls exif_read_data only for appropriate
formats.

Previously, the function was also called with formats that can not
contain EXIF data. This resulted in warnings.
This commit is contained in:
Oliver Vogel
2024-06-29 09:51:20 +02:00
committed by GitHub
parent c7fb60e6c9
commit 137bdb356a
4 changed files with 26 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Modifiers\AlignRotationModifier;
class BinaryImageDecoder extends NativeObjectDecoder implements DecoderInterface
@@ -48,17 +49,17 @@ class BinaryImageDecoder extends NativeObjectDecoder implements DecoderInterface
// create image instance
$image = parent::decode($gd);
// extract & set exif data
$image->setExif($this->extractExifData($input));
// get media type
$mediaType = $this->getMediaTypeByBinary($input);
try {
// set mediaType on origin
$image->origin()->setMediaType(
$this->getMediaTypeByBinary($input)
);
} catch (DecoderException) {
// extract & set exif data for appropriate formats
if (in_array($mediaType->format(), [Format::JPEG, Format::TIFF])) {
$image->setExif($this->extractExifData($input));
}
// set mediaType on origin
$image->origin()->setMediaType($mediaType);
// adjust image orientation
if ($this->driver()->config()->autoOrientation) {
$image->modify(new AlignRotationModifier());

View File

@@ -40,8 +40,10 @@ class FilePathImageDecoder extends NativeObjectDecoder implements DecoderInterfa
$image->origin()->setFilePath($input);
$image->origin()->setMediaType($mediaType);
// extract exif
$image->setExif($this->extractExifData($input));
// extract exif for the appropriate formats
if ($mediaType->format() === Format::JPEG) {
$image->setExif($this->extractExifData($input));
}
// adjust image orientation
if ($this->driver()->config()->autoOrientation) {

View File

@@ -7,8 +7,10 @@ namespace Intervention\Image\Drivers\Imagick\Decoders;
use Imagick;
use ImagickException;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\MediaType;
class BinaryImageDecoder extends NativeObjectDecoder
{
@@ -28,8 +30,13 @@ class BinaryImageDecoder extends NativeObjectDecoder
// decode image
$image = parent::decode($imagick);
// extract exif data
$image->setExif($this->extractExifData($input));
// get media type enum from string media type
$mediaType = MediaType::from($image->origin()->mediaType());
// extract exif data for appropriate formats
if (in_array($mediaType->format(), [Format::JPEG, Format::TIFF])) {
$image->setExif($this->extractExifData($input));
}
return $image;
}

View File

@@ -31,8 +31,10 @@ class FilePathImageDecoder extends NativeObjectDecoder
// set file path on origin
$image->origin()->setFilePath($input);
// extract exif data
$image->setExif($this->extractExifData($input));
// extract exif data for the appropriate formats
if (in_array($imagick->getImageFormat(), ['JPEG', 'TIFF', 'TIF'])) {
$image->setExif($this->extractExifData($input));
}
return $image;
}