失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php获取图片宽高相反 exif_read_data()解决上传图片旋转 图片反向问题 getimagesiz

php获取图片宽高相反 exif_read_data()解决上传图片旋转 图片反向问题 getimagesiz

时间:2018-12-02 04:19:25

相关推荐

php获取图片宽高相反 exif_read_data()解决上传图片旋转 图片反向问题 getimagesiz

PHP getimagesize 函数获取的图像宽高反了?

exif_read_data()解决上传图片旋转、图片反向问题,getimagesize获取图片高度宽度相反的问题,手机图片上传之后出现了反向问题,操作系统里的文件属性功能可能已经把图片给修正过了,那这时候就要把图片给旋转回来就需要用到php的exif_read_data方法。

返回结果:

Array

(

[FileName] => phpx7iokl

[FileDateTime] => 1558932683

[FileSize] => 3896832

[FileType] => 2

[MimeType] => image/jpeg

[SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP

[COMPUTED] => Array

(

[html] => width="4000" height="3000"

[Height] => 3000

[Width] => 4000

[IsColor] => 1

[ByteOrderMotorola] => 1

[ApertureFNumber] => f/1.8

[Thumbnail.FileType] => 2

[Thumbnail.MimeType] => image/jpeg

)

[Model] => MI 6X

[Software] => wayne-user 9 PKQ1.180904.001 V10.3.2.0.PDCCNXM release-keys

[Orientation] => 6

[DateTime] => :05:26 15:30:57

[YCbCrPositioning] => 1

[Exif_IFD_Pointer] => 255

[ResolutionUnit] => 2

[GPS_IFD_Pointer] => 798

[XResolution] => 72/1

[YResolution] => 72/1

[Make] => Xiaomi

[THUMBNAIL] => Array

(

[JPEGInterchangeFormat] => 969

[Orientation] => 6

[JPEGInterchangeFormatLength] => 12256

[Compression] => 6

[ResolutionUnit] => 2

[XResolution] => 72/1

[YResolution] => 72/1

)

[ISOSpeedRatings] => 400

[ExposureProgram] => 0

[FNumber] => 175/100

[ExposureTime] => 1/50

[UndefinedTag:0x9999] => {"sensor_type":"rear","mirror":false}

[SensingMethod] => 2

[SubSecTimeDigitized] => 732806

[SubSecTimeOriginal] => 732806

[SubSecTime] => 732806

[FocalLength] => 4070/1000

[Flash] => 16

[UndefinedTag:0x8889] => HHT

[MeteringMode] => 2

[SceneCaptureType] => 0

[InteroperabilityOffset] => 768

[FocalLengthIn35mmFilm] => 4

[DateTimeDigitized] => :05:26 15:30:57

[ExifImageLength] => 3000

[WhiteBalance] => 0

[DateTimeOriginal] => :05:26 15:30:57

[BrightnessValue] => -97/100

[ExifImageWidth] => 4000

[ExposureMode] => 0

[ApertureValue] => 161/100

[ComponentsConfiguration] =>

[ColorSpace] => 1

[SceneType] =>

[ShutterSpeedValue] => 5643/1000

[ExifVersion] => 0220

[FlashPixVersion] => 0100

[GPSTimeStamp] => Array

(

[0] => 7/1

[1] => 30/1

[2] => 56/1

)

[GPSDateStamp] => :05:26

[InterOperabilityIndex] => R98

[InterOperabilityVersion] => 0100

)

//获取图片的旋转角度

$rotate = 0;

$orientation = 1;

if (function_exists('exif_read_data')) {

try { //这里使用try catch主要是解决iphone手机不支持这个方法

$exif = exif_read_data($tep_name);

} catch (Exception $exp) {

$exif = false;

}

if ($exif && isset($exif['Orientation'])){

$orientation = $exif['Orientation'];

}

} else if (preg_match('@\x12\x01\x03\x00\x01\x00\x00\x00(.)\x00\x00\x00@', file_get_contents($tep_name), $matches)) {

$orientation = ord($matches[1]);

}

//获取角度

switch($orientation) {

case 1:

$rotate = 0;

break;

case 8:

$rotate = -90;

break;

case 3:

$rotate = 0;

break;

case 6:

$rotate = 90;

break;

}

?>

问题解决方案参考:https://www.e-/content/wangluowenzhang/717898

参考文档:/csonezp/p/5564809.html

php获取图片宽高相反 exif_read_data()解决上传图片旋转 图片反向问题 getimagesize获取图片高度宽度相反的问题...

如果觉得《php获取图片宽高相反 exif_read_data()解决上传图片旋转 图片反向问题 getimagesiz》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。