In writing a PHP to the direction of the image according to the EXIF rotation function, the function is done, but after the rotation of the picture file exif information is gone, because I use
imagejpegRewrite the picture, how can I write exif back?
Post the code for the picture I rotated:
function rotateImg($img,$degrees,$bgd_color=0,$ignore_transparent=null){ $resource = imagecreatefromjpeg($img); //$resource = imagecreatefromstring(file_get_contents($img)); if(!$resource) return false; $resource = imagerotate($resource, $degrees, $bgd_color,$ignore_transparent); print_r($img); if($resource&&imagejpeg($resource,$img)){ imagedestroy($resource);//释放内存 return true; } return false;}
Reply content:
In writing a PHP to the picture direction according to the function of the EXIF rotation, the function is done, but the picture file after the rotation of EXIF information is gone, because I used to imagejpeg rewrite the picture, how to write Exif back?
Post the code for the picture I rotated:
function rotateImg($img,$degrees,$bgd_color=0,$ignore_transparent=null){ $resource = imagecreatefromjpeg($img); //$resource = imagecreatefromstring(file_get_contents($img)); if(!$resource) return false; $resource = imagerotate($resource, $degrees, $bgd_color,$ignore_transparent); print_r($img); if($resource&&imagejpeg($resource,$img)){ imagedestroy($resource);//释放内存 return true; } return false;}
It is easy to read/write EXIF information with Imagick.
http://php.net/manual/en/imagick.setimageproperty.php
GD is not supported for EXIF writing and can only be read.
Compared to the Gd,imagick is too advanced. Change it.