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 ?
LVL 1
JoshWegenerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.