• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1121
  • Last Modified:

PHP - How to store data inside a JPG Image

ok, so I have a JPG image, I want to be able to store data inside this image... like a description or somthing... how would go about storing this data inside the image so I can read / set it using PHP?

If I have more data (not just a description) where / how can I store that data in the image ?
0
JoshWegener
Asked:
JoshWegener
  • 3
  • 2
1 Solution
 
Roger BaklundCommented:
There is a standard php function for this, called iptcembed(). It is not very easy to use, but there are third party libraries which can be used.

http://php.net/iptcembed
http://cvs.php.net/viewvc.cgi/pear/Image_IPTC/

Download IPCT.php and use code like this:
<?php
include('IPTC.php');
$img = new Image_IPTC('photo\P6170096.JPG');
 
// write caption
$img->setTag('caption','Description of the image.');
$img->save();
 
// read caption
echo $img->getTag('caption');  # outputs 'Description of the image.'
 
?>

Open in new window

0
 
JoshWegenerAuthor Commented:
Aww, I love this... Thanks!

I take it this only works for JPG ? What about PNG ? or TIFF ? BMP ?
0
 
Roger BaklundCommented:
No, only jpeg.
0
 
JoshWegenerAuthor Commented:
When I look at the code (IPTC.php) - it appears you can only use predefined tags... is this true? or can you add your own to that list?
0
 
Roger BaklundCommented:
To maintain compatibillity with other software, you must use predefined tags. But for your own usage, you could create custom tags.

Note that IPTC as such is not limited to jpeg, but this particular function is.

http://en.wikipedia.org/wiki/IPTC_(image_meta-data)
http://www.iptc.org/
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now