Tagging images with php

I would like to write a script that can tag images and save the tag in FILE , and not in an external database. I will also need to read tags from a file through php.

Why do I want to do this?

Right-click on the image and select properties, then click on the details, then click on the tags and THEN adding your tags is tiring, to say the least. I cannot find a shortcut to quickly add tags in windows, so I want to write my own script that can do this.

Is it possible?

I don’t know if this is the case, whenever I search for images and tags on the same line, I get image tags for html tutorials or people storing tags in an external database. I cannot find good resources, if someone can offer some that I can look at, I would be grateful.

What do I have so far?

I can list all the images on my hdd and click on the image, and a popup window will appear for me to enter the tag. Then I send this tag to the php file, waiting for me to do something with it ...

Why don't I want to save tags in an external database?

I will not start my localhost all the time. If I copy images, tags must come with.

Any information on this would be great.

+7
jquery windows filesystems php image
source share
2 answers

you can use

iptcembed to insert IPTC binary data into exif-read-data JPEG image to read EXIF ​​headers from JPEG or TIFF

How to read a title tag from a JPEG file

getimagesize('./phplogo.jpg', $info); $title = ''; if (isset($info["APP13"])) { $iptc = iptcparse ($info["APP13"]); $title = (isset($iptc["2#085"][0])) ? $iptc["2#085"][0] : NULL; } print $title; 

How to add title tag to JPEG
Notes. You only need to manipulate the $ iptc array and specify the file path
This is a working example from iptcembed

 // iptc_make_tag() function by 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 to jpeg file $path = './phplogo.jpg'; // Set the IPTC tags $iptc = array( '2#085' => 'Anis TITLE' ); // Convert the IPTC tags into binary code $data = ''; foreach($iptc as $tag => $string) { $tag = substr($tag, 2); $data .= iptc_make_tag(2, $tag, $string); } // Embed the IPTC data $content = iptcembed($data, $path); // Write the new image data out to the file. $fp = fopen($path, "wb"); fwrite($fp, $content); fclose($fp); 

Here is a complete list of IPTC indices

 DEFINE('IPTC_OBJECT_NAME', '2#005'); DEFINE('IPTC_EDIT_STATUS', '2#007'); DEFINE('IPTC_PRIORITY', '2#010'); DEFINE('IPTC_CATEGORY', '2#015'); DEFINE('IPTC_SUPPLEMENTAL_CATEGORY', '2#020'); DEFINE('IPTC_FIXTURE_IDENTIFIER', '2#022'); DEFINE('IPTC_KEYWORDS', '2#025'); DEFINE('IPTC_RELEASE_DATE', '2#030'); DEFINE('IPTC_RELEASE_TIME', '2#035'); DEFINE('IPTC_SPECIAL_INSTRUCTIONS', '2#040'); DEFINE('IPTC_REFERENCE_SERVICE', '2#045'); DEFINE('IPTC_REFERENCE_DATE', '2#047'); DEFINE('IPTC_REFERENCE_NUMBER', '2#050'); DEFINE('IPTC_CREATED_DATE', '2#055'); DEFINE('IPTC_CREATED_TIME', '2#060'); DEFINE('IPTC_ORIGINATING_PROGRAM', '2#065'); DEFINE('IPTC_PROGRAM_VERSION', '2#070'); DEFINE('IPTC_OBJECT_CYCLE', '2#075'); DEFINE('IPTC_BYLINE', '2#080'); DEFINE('IPTC_BYLINE_TITLE', '2#085'); DEFINE('IPTC_CITY', '2#090'); DEFINE('IPTC_PROVINCE_STATE', '2#095'); DEFINE('IPTC_COUNTRY_CODE', '2#100'); DEFINE('IPTC_COUNTRY', '2#101'); DEFINE('IPTC_ORIGINAL_TRANSMISSION_REFERENCE', '2#103'); DEFINE('IPTC_HEADLINE', '2#105'); DEFINE('IPTC_CREDIT', '2#110'); DEFINE('IPTC_SOURCE', '2#115'); DEFINE('IPTC_COPYRIGHT_STRING', '2#116'); DEFINE('IPTC_CAPTION', '2#120'); DEFINE('IPTC_LOCAL_CAPTION', '2#121'); 
+2
source share

You can use PHPExiftool to write metadata to a file as follows (quote from the github page):

 <?php require __DIR__ . '/vendor/autoload.php'; use Monolog\Logger; use PHPExiftool\Writer; use PHPExiftool\Driver\Metadata\Metadata; use PHPExiftool\Driver\Metadata\MetadataBag; use PHPExiftool\Driver\Tag\IPTC\ObjectName; use PHPExiftool\Driver\Value\Mono; $logger = new Logger('exiftool'); $Writer = Writer::create($logger); $bag = new MetadataBag(); $bag->add(new Metadata(new ObjectName(), new Mono('Pretty cool subject'))); $Writer->write('image.jpg', $bag); 

And if you want to track the metadata that you wrote, you can easily use the php md5_file () function to get the ID of the file whose metadata you changed, and then write a line in the text file with the hash given, followed by the metadata that you wrote separated by a separator, such as "," (comma). Each line in this text file will represent a file modified by your script.

+2
source share

All Articles