开发者

How can I add metadata to an image?

开发者 https://www.devze.com 2023-01-11 17:49 出处:网络
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.Php integration into images ;)

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.


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.


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/


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.


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.


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


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消