Writing Exif Data in PHP

Write EXIF into JPG with PHP

The only way I've found is to install PEL - the PHP Exif Library

Creating an image of PNG-format in php with GD with exif

u can go through the following link
exif is not used in png.

https://stackoverflow.com/questions/9542359/does-png-contain-exif-data-like-jpg

but now a days some png image preserve exif tag.u can try bellow link it might help
http://php.net/manual/en/function.exif-read-data.php

Following is the sample code

<?php
//path of the image
$image_name = "1.PNG";

//read all the image attributes
$exif = exif_read_data($image_name, 0, true);
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers\n";

//print the name of the image
echo "Image Name:".$image_name."\n\n";

//iterate trough the image to list all the attributes
foreach ($exif as $key => $section) {
echo "############### Section Name :".$key." #############\n";
foreach ($section as $name => $val) {
echo "$key.$name: $val\n";
}
echo "\n";
}

?>

This will gives bellow output

Image contains headers
Image Name:1.PNG

############### Section Name :FILE #############
FILE.FileName: 1.PNG
FILE.FileDateTime: 1511089868
FILE.FileSize: 6251146
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, EXIF, MAKERNOTE

############### Section Name :COMPUTED #############
COMPUTED.html: width="5184" height="3456"
COMPUTED.Height: 3456
COMPUTED.Width: 5184
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 0
COMPUTED.ApertureFNumber: f/5.0

############### Section Name :IFD0 #############
IFD0.Make: Canon
IFD0.Model: Canon EOS 1300D
IFD0.Orientation: 1
IFD0.XResolution: 72/1
IFD0.YResolution: 72/1
IFD0.ResolutionUnit: 2
IFD0.DateTime: 2017:11:19 16:41:08
IFD0.Artist:
IFD0.YCbCrPositioning: 2
IFD0.Copyright:

############### Section Name :EXIF #############
EXIF.ExposureTime: 1/60
EXIF.FNumber: 5/1
EXIF.ExposureProgram: 2
EXIF.ISOSpeedRatings: 800
EXIF.UndefinedTag:0x8830: 2
EXIF.UndefinedTag:0x8832: 800
EXIF.ExifVersion: 0230
EXIF.DateTimeOriginal: 2017:11:19 16:41:08
EXIF.DateTimeDigitized: 2017:11:19 16:41:08
EXIF.ComponentsConfiguration:

I hope this might help

How do I add exif data to an image?

You can save a large amount of space, especially if you have a large number of images..

Add the following to text.txt (format of the IPTC tags taken from here):

2#110#Credit="My Company"
2#05#Object Name="THE_OBJECT_NAME"
2#55#Date Created="2011-02-03 12:45"
2#80#By-line="BY-LINE?"
2#110#Credit="The CREDIT"
2#115#Source="SOURCE"
2#116#Copyright Notice="THE COPYRIGHT"
2#118#Contact="THE CONTACT"
2#120#Caption="AKA Title"

Strip all existing exif data from the image

mogrify -strip image.jpg

Add the credit to your image

mogrify -profile 8BIMTEXT:text.txt image.jpg

How to add keywords in image file with PHP?

So, you cannot use ImageMagick to do what you are trying to do and that is a bummer -- but that does not mean you are out of options. You have two that I can think of off the top of my head for dealing with EXIF and ITPC data in JPEG images:

  1. Use a 3rd party PHP library designed to work with EXIF data. The one I am specifically thinking of is called Pel and supports JPEG and TIFF images. From what I have read, it can be tricky to use and the documentation is sparse, but may be worth a try.

  2. Another option is called ExifTool, a handy command line utility that actually supports, EXIF, ITPC, XMP, among others (don't let the name fool you). If you add this command line tool to your server, you can then call it via PHP shell type commands and process the image that way. Just be aware that if the image is user input, you must be very careful to validate the image is actually an image, that the exif data doesn't have a payload injected, and do your absolute best to try to write as secure code as possible. One bit of code I found online calls ExifTool using exec(), but also calls escapeshellcommand() to clean the arguments when building the call. I suspect if you dig further up in that code, the images themselves are also being validated with things like getimagesize() and other techniques.

Remove EXIF data from JPG using PHP

Use gd to recreate the graphical part of the image in a new one, that you save with another name.

See PHP gd


edit 2017

Use the new Imagick feature.

Open Image:

<?php
$incoming_file = '/Users/John/Desktop/file_loco.jpg';
$img = new Imagick(realpath($incoming_file));

Be sure to keep any ICC profile in the image

    $profiles = $img->getImageProfiles("icc", true);

then strip image, and put the profile back if any

    $img->stripImage();

if(!empty($profiles)) {
$img->profileImage("icc", $profiles['icc']);
}

Comes from this PHP page, see comment from Max Eremin down the page.



Related Topics



Leave a reply



Submit