PHP writes and reads the custom image information _ exif or something.

Source: Internet
Author: User
PHP writes and reads image user-defined information _ exif or something? Requirement: use PHP to optimize image files. However, this optimization process can only be performed once. secondary optimization will cause irreparable damage to images. It is expected that after an image is processed, a custom string will be written into the image file. it can be used only to determine whether the image has been processed. We look forward to using PHP for solutions. Currently, I want to write the custom _ exif or something into J PHP to read the image?
Requirement description:

PHP is used to optimize image files, but this optimization process can only be performed once. secondary operations will cause irreparable damage to images. It is expected that after an image is processed, a custom string will be written into the image file. it can be used only to determine whether the image has been processed.


We look forward to using PHP for solutions. Currently, if you want to use the JPEG format, you can use the EXIF information to write a custom string in the EXIF information. But how can we solve common network Image formats like GIF, PNG, and BMP?

Google is here
Imagick: setImageProperty

According to document http://www.php.net/manual/zh/imagick.setimageproperty.php

It seems to have met the requirements, but I am not sure if I am using this function to save the image and read it again.


$image = new Imagick($file);
$image->setImageProperty('Exif:Make', 'Imagick');
$image->writeImage($file2);

$image2 = new Imagick($file2);
echo $image->getImageProperty('Exif:Make');



This is an idea, but it cannot be implemented. I really hope there is a problem with my usage, not that this function cannot be implemented.

Try APP13 again


$size = getimagesize('1.jpg', $info);

var_dump($size);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    var_dump($iptc);
}


But it does not.

Have I been on a detour? Is there any good way? There are not many requirements, that is, to write a string in the image data on the basis of the fast image, for the next time to read this string.

Let's show up and give some advice to solve the problem.
PHP image sharing:
------ Solution --------------------
For images supported by GD, you can append custom data after the image data ends without affecting the image content.
Sample code
$ Url = 'http: // avatar.profile.csdn.net/0/e/f/?jaylecn.jpg ';
$ Im = imagecreatefromjpeg ($ url );
Imagepng ($ im, 'test.png '); // Generate a png image file
$ S = 'abcefg'; // the information to be appended.
File_put_contents('test.png ', sprintf (' % sInfo % s', $ s, pack ('N', strlen ($ s), FILE_APPEND ); // Append the image file in a custom format

// Read back
$ S = file_get_contents('test.png ');
$ T = unpack ('a4t/noffs', substr ($ s,-6); // Retrieve the length of custom information
$ V = substr ($ s,-6-$ t ['offs'],-6); // retrieve custom information
Echo $ v; // abcdef

Verify that the image data is not damaged.
------ Solution --------------------
In fact, there is a general concept: streaming data can be read and displayed while reading. the header file shows the mimetype and length (or the ending mark ), the "extra" data after the length (or ending sign) does not affect the display of the subject Data. in this case, even rar and zip data can be used.

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.