Home > Backend Development > PHP Tutorial > php如何给jpg图片写入exif信息?

php如何给jpg图片写入exif信息?

WBOY
Release: 2016-06-06 20:19:43
Original
1960 people have browsed it

在写一个php把图片方向根据exif旋转过来的功能,功能是做好了,但是旋转之后的图片文件exif信息都没了,因为我用imagejpeg重写了图片,请问怎么把exif写回去?

贴一下我旋转图片的代码:

<code>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;
}</code>
Copy after login
Copy after login

回复内容:

在写一个php把图片方向根据exif旋转过来的功能,功能是做好了,但是旋转之后的图片文件exif信息都没了,因为我用imagejpeg重写了图片,请问怎么把exif写回去?

贴一下我旋转图片的代码:

<code>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;
}</code>
Copy after login
Copy after login

用Imagick可以很方便的读取/写入EXIF信息。
http://php.net/manual/en/imagick.setimageproperty.php

Gd是不支持exif写入的,只能读取。

相比Gd,Imagick实在是太先进了。换吧。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template