image - PHP EXIF Manipulation -
i working on image upload website, trying ensure works mobile device well.however have been looking @ of metadata being stored in photos , not fan of gps locations going along simple photos.
i decided create new photo using:
html:
<form id="frmimageupload" action="uploadim.php" method="post" enctype="multipart/form-data"> <label for="filetoupload">file::</label><br> <input type="file" name="filetoupload" id="filetoupload"><br> <input type="submit" value="submit" name="submit" onclick=" return validatedata(**this returns true , submits form**)">
uploadim.php php:
<?php $imageobject = imagecreatefromjpeg($_files["filetoupload"]["tmp_name"]); imagejpeg($imageobject, $target_file, 75); ?>
all works point , image created. there no more exif data. gps info gone, great. orientation value gone. no good.
i found page on how manipulate exif data:
http://php.net/manual/en/function.iptcembed.php
i integrated , began examine how worked.
<?php $imageobject = imagecreatefromjpeg($_files["filetoupload"]["tmp_name"]); imagejpeg($imageobject, $target_file, 75); // iptc_make_tag() function thies c. arntzen function iptc_make_tag($rec, $data, $value) { $length = strlen($value); $retval = chr(0x1c) . chr($rec) . chr($data); if($length < 0x8000) { $retval .= chr($length >> 8) . chr($length & 0xff); } else { $retval .= chr(0x80) . chr(0x04) . chr(($length >> 24) & 0xff) . chr(($length >> 16) & 0xff) . chr(($length >> 8) & 0xff) . chr($length & 0xff); } return $retval . $value; } // path jpeg file $path = $target_file; // set iptc tags $iptc = array( '2#120' => 'test image', '2#116' => 'copyright 2008-2009, php group', ); // convert iptc tags binary code $data = ''; foreach($iptc $tag => $string) { $tag = substr($tag, 2); $data .= iptc_make_tag(2, $tag, $string); } // embed iptc data $content = iptcembed($data, $path); // write new image data out file. $fp = fopen($path, "wb"); fwrite($fp, $content); fclose($fp);
this works fine , able change copyright data of image after saving specified folder. question how might go changing orientation of image? image in portrait mode . when upload server saves landscape? have tried replacing:
$iptc = array( '2#120' => 'test image', '2#116' => 'copyright 2008-2009, php group', ); // convert iptc tags binary code $data = ''; foreach($iptc $tag => $string) { $tag = substr($tag, 2); $data .= iptc_make_tag(2, $tag, $string); }
with:
$iptc = array( '2#131' => 'p' ); // convert iptc tags binary code $data = ''; foreach($iptc $tag => $string) { $tag = substr($tag, 2); $data .= iptc_make_tag(2, $tag, $string); }
or
$iptc = array( '2#131' => '6' ); // convert iptc tags binary code $data = ''; foreach($iptc $tag => $string) { $tag = substr($tag, 2); $data .= iptc_make_tag(2, $tag, $string); }
in accordance information read exif data here: https://sno.phy.queensu.ca/~phil/exiftool/tagnames/jpeg.html
and
http://www.vcode.no/web/resource.nsf/ii2lnug/643.htm
i familiar imagick , other libraries can download. trying figure out if there simple step completing base php im using , gd. since 95% complete task minus image rotation.
Comments
Post a Comment