7

Where does one insert meta data into and image file and what it the mark up to do so? i want to do this with php.

2
  • 2
    What type of imagery are you dealing with? PNGs? Bitmaps? JPEGs? Aug 11, 2010 at 19:50
  • @Thomas Owens - I think they mean more non-binary metadata, like <meta> tags or alt attributes... Aug 11, 2010 at 19:56

6 Answers 6

5
+25

Php integration into images ;)

http://bechtsoudis.com/archive/2011/09/08/php-code-into-jpeg-metadata-from-hide-to-unhide/index.html

JPEG, TIFF, PSD, Raw and several other file formats can include any or all the following standard types of metadata:

IPTC-IIM Often called "legacy" IPTC, this schema was developed in the early 1990s, primarily to aid news organizations in captioning early digital images. Its primary advantage is that most image editing and management programs can read and write its widely compatible fields.

IPTC Core & Extension This newer schema builds on the legacy of IIM by adding more types of descriptive and administrative information, including new fields to accommodate the needs of the stock photography and cultural heritage communities, packaged in a more robust data format, "XMP."

PLUS The Picture Licensing Universal System for identifying and defining image-use licenses, describes a schema and tools for generating a string of characters that can identify a copyright holder, user, scope and terms of a licensed image use.

XMP This is the newer data format used by IPTC Core and Extension for storing and accessing image metadata. It enables metadata storage within an image file or in an accompanying sidecar file, and it permits creation of custom metadata fields.

Exif These metadata, often created by cameras and other capture devices, include technical information about an image and its capture method, such as exposure settings, capture time, GPS location information and camera model.

Dublin Core Many image libraries and a wide variety of industries store information with image files using this schema. Several of its fields are interoperable with IPTC formats.

3
2

You can use image libraries like imagemagick

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=20183

There is another tool I know named Jhead which can retieve and modify some metadata if images

http://www.sentex.net/~mwandel/jhead/

2

You can go for iptcembed function in PHP to add information to image. usage could be found at: http://php.net/manual/en/function.iptcembed.php

Added data could be retrieved using iptcparse function.

Let me know if this works for you.

1
  • +1 for IPTC embed but unfortunately iptcembed is not enough to manipulate on most cases also has problems with multibyte header data. and only supports JPEG. more: iptc.org. i advice to use imagemagick with a simple php wrapper. which will be much more effective on memory usage & performance & availability
    – risyasin
    Sep 15, 2013 at 15:15
1

You can opt for a simpler alternative, that will use the exiftool command line tool.

To use it, I have coded today for a personal project a simple PHP script that will write the Latitude/Longitude info, if you already have it in PHP variables.

And, which is very important, a way of adding the GPSLatitudeRef and GPSLongitudeRef values based on the previous ones. Basically, if the Latitude is positive, then GPSLatitudeRef should have the "North" value, and "South" if negative. For GPSLongitudeRef is the same, but being "East" when positive, and "West" when negative.

$bashExifEdit = "";
$longitudeRef = "East";
if ($longitude < 0) {
    $longitudeRef = "West";
}
$latitudeRef = "North";
if ($latitude < 0) {
    $latitudeRef = "South";
}

if ($sleepingPlace != null) {
    $bashExifEdit .= "exiftool -GPSLongitude=\"".$longitude."\"  -GPSLatitude=\"".$latitude.".\" -GPSLatitudeRef=\"$latitudeRef\" -GPSLongitudeRef=\"$longitudeRef\"  images/your_image.jpg\n";
}

This will generate a string, with and endline character for each image. If you add a for then you can just write to it the content of $bashExifEdit, and voilà! An automated way of setting all the GPS details (except the altitude, which is not that different than the latitude/longitude) based on a latitude/longitude for your images.

0

I recently saw a really cool article on the w3c blog about combining RDFa and an HTML <imagemap> to enrich images by specifying not only what's in the image but also where it is in the image: http://www.w3.org/QA/2008/01/rdfa_and_html_imagemap.html

-1

In PHP you can use headers:

example:

 header('Content-Length: ' . filesize($file));  /// that's the file size 

You can add more headers like that one and it will work.You can even send some custom headers and it will still work :)

1
  • It won't make metadata part of the image file, but part of the HTTP response, so they will be lost if user saves the file image. Not mentionning that custom HTTP headers must start with a X-
    – Xenos
    May 19, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.