mirror of
https://github.com/Intervention/image.git
synced 2025-08-22 21:42:53 +02:00
Add Image::readExif()
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace Intervention\Image\Drivers\Abstract;
|
||||
|
||||
use Exception;
|
||||
use Intervention\Gif\Exception\NotReadableException;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Exceptions\NotSupportedException;
|
||||
use Intervention\Image\Geometry\Circle;
|
||||
use Intervention\Image\Geometry\Ellipse;
|
||||
use Intervention\Image\Geometry\Line;
|
||||
@@ -348,6 +351,41 @@ abstract class AbstractImage implements ImageInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read exif data from current image instance
|
||||
*
|
||||
* Returns value of given key or null if key was not found. If no
|
||||
* parameter is given an array of all available data is returned.
|
||||
*
|
||||
* @param null|string $tag
|
||||
* @return mixed
|
||||
* @throws NotSupportedException
|
||||
* @throws NotReadableException
|
||||
*/
|
||||
public function readExif(?string $tag = null): mixed
|
||||
{
|
||||
if (!function_exists('exif_read_data')) {
|
||||
throw new NotSupportedException(
|
||||
'Reading Exif data is not supported by this PHP installation.'
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$pointer = $this->toJpeg()->toFilePointer();
|
||||
$data = @exif_read_data($pointer);
|
||||
} catch (Exception $e) {
|
||||
throw new NotReadableException('Unable to read Exif data from this image.');
|
||||
}
|
||||
|
||||
fclose($pointer);
|
||||
|
||||
if (!is_null($tag) && is_array($data)) {
|
||||
$data = array_key_exists($tag, $data) ? $data[$tag] : null;
|
||||
}
|
||||
|
||||
return is_array($data) ? new Collection($data) : $data;
|
||||
}
|
||||
|
||||
public function destroy(): void
|
||||
{
|
||||
$this->modify(
|
||||
|
8
src/Exceptions/NotSupportedException.php
Normal file
8
src/Exceptions/NotSupportedException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Exceptions;
|
||||
|
||||
class NotSupportedException extends \RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
Reference in New Issue
Block a user