How does PHP write exif information to JPG images?

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.