forked from leftypol/leftypol
DefaultImageMetadataReader.php: adkust width and height according to exif orientation
This commit is contained in:
parent
72fcf970c3
commit
1794ac4334
1 changed files with 17 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\Driver\ExifReaderFactory;
|
||||
use Vichan\Data\Exif;
|
||||
use Vichan\Data\ImageMetadataResult;
|
||||
|
||||
|
||||
|
@ -29,9 +30,22 @@ class DefaultImageMetadataReader implements ImageMetadataReader {
|
|||
if ($ret[2] == \IMAGETYPE_UNKNOWN) {
|
||||
throw new \RuntimeException("Error '$file_path' is not an image");
|
||||
}
|
||||
$exif_reader = $this->exif_reader_factory->getReader($ret['mime']);
|
||||
$orientation = $exif_reader === null ? null : $exif_reader->getOrientation($file_path);
|
||||
|
||||
return new ImageMetadataResult($ret[0], $ret[1], $ret['mime'], $orientation);
|
||||
$width = $ret[0];
|
||||
$height = $ret[1];
|
||||
$mime = $ret['mime'];
|
||||
$orientation = null;
|
||||
|
||||
$exif_reader = $this->exif_reader_factory->getReader($mime);
|
||||
if ($exif_reader !== null) {
|
||||
$orientation = $exif_reader->getOrientation($file_path);
|
||||
if ($orientation !== null && Exif::exifOrientationOnSide($orientation)) {
|
||||
$tmp = $width;
|
||||
$width = $height;
|
||||
$height = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return new ImageMetadataResult($width, $height, $mime, $orientation);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue