mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-09 14:38:27 +03:00
Improved error handling for exif_read_data() File not supported
This commit is contained in:
parent
d2e69d7459
commit
b326fb5af4
3 changed files with 36 additions and 9 deletions
31
snappymail/v/0.0.0/app/libraries/snappymail/image/exif.php
Normal file
31
snappymail/v/0.0.0/app/libraries/snappymail/image/exif.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace SnappyMail\Image;
|
||||
|
||||
class Exif
|
||||
{
|
||||
/*
|
||||
const
|
||||
ORIENTATION_UNDEFINED = 0,
|
||||
ORIENTATION_TOPLEFT = 1,
|
||||
ORIENTATION_TOPRIGHT = 2,
|
||||
ORIENTATION_BOTTOMRIGHT = 3,
|
||||
ORIENTATION_BOTTOMLEFT = 4,
|
||||
ORIENTATION_LEFTTOP = 5,
|
||||
ORIENTATION_RIGHTTOP = 6,
|
||||
ORIENTATION_RIGHTBOTTOM = 7,
|
||||
ORIENTATION_LEFTBOTTOM = 8;
|
||||
*/
|
||||
public static function getImageOrientation(string &$data, array $image_info = null) : int
|
||||
{
|
||||
$image_info = empty($image_info['mime']) ? \getimagesizefromstring($data) : $image_info;
|
||||
if (!empty($image_info['mime']) && \is_callable('exif_read_data')) {
|
||||
$exif = \exif_read_data('data://'.$image_info['mime'].';base64,' . \base64_encode($data));
|
||||
if (false !== $exif) {
|
||||
return \max(0, \intval($exif['IFD0.Orientation'] ?? 0));
|
||||
}
|
||||
\error_log("{$image_info['mime']} " . \error_get_last()['message']);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ class GD2 implements \SnappyMail\Image
|
|||
$file,
|
||||
$format,
|
||||
$compression_q = 85,
|
||||
$orientation = 1,
|
||||
$orientation = 0,
|
||||
$type;
|
||||
|
||||
function __destruct()
|
||||
|
|
@ -51,9 +51,7 @@ class GD2 implements \SnappyMail\Image
|
|||
$gd2->file = 'blob';
|
||||
$gd2->type = (int) $imginfo[2];
|
||||
$gd2->format = $format;
|
||||
if (\is_callable('exif_read_data') && $exif = \exif_read_data('data://'.$imginfo['mime'].';base64,' . \base64_encode($data))) {
|
||||
$gd2->orientation = \max(1, \intval($oMetadata['IFD0.Orientation'] ?? 0));
|
||||
}
|
||||
$gd2->orientation = Exif::getImageOrientation($data, $imginfo);
|
||||
return $gd2;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ if (!\class_exists('Gmagick',false)) { return; }
|
|||
class GMagick extends \Gmagick implements \SnappyMail\Image
|
||||
{
|
||||
private
|
||||
$orientation = 1;
|
||||
$orientation = 0;
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
|
|
@ -22,10 +22,8 @@ class GMagick extends \Gmagick implements \SnappyMail\Image
|
|||
}
|
||||
if (\method_exists($gmagick, 'getImageOrientation')) {
|
||||
$gmagick->orientation = $gmagick->getImageOrientation();
|
||||
} else if (\is_callable('exif_read_data') && $imginfo = \getimagesizefromstring($data)) {
|
||||
if ($exif = \exif_read_data('data://'.$imginfo['mime'].';base64,' . \base64_encode($data))) {
|
||||
$gmagick->orientation = \max(1, \intval($exif['IFD0.Orientation'] ?? 0));
|
||||
}
|
||||
} else {
|
||||
$gd2->orientation = Exif::getImageOrientation($data);
|
||||
}
|
||||
return $gmagick;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue