...

View Full Version : extracting attributes from jpeg file



malcolm_macaula
04-17-2003, 12:36 AM
Hi All,

Does anyone know how to programmatically (javascript, vb, whatever..) extract the 'additional' attributes contained in a .jpg file?

What do I mean by 'additional' attributes - when you view the properties of a .jpg in windows you can see additional attributes such as:

- Date Picture Taken
- Horizontal Resolution
- Shutter Speed

etc. I want to extract some of these properties via code so they can be displayed on a photo gallery website.

Thanks in advance.

cheers

Malcolm

Feyd
04-17-2003, 07:10 AM
You can't do this with graphics, you have to use server side code to query the image itself (possibly in conjunction with a DB) in order to get that information. In PHP it would be simple:



$imagepath = '/full/image/path/to.gif';
$imgxy = getimagesize($imagepath);
//$imgxy[0] = width
//$imgxy[1] = height
//$imgxy[2] = image type: a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF
//$imgxy[3] = 'width="xx" height="xx"' for use in SRC

echo 'last modified: ' . date ('F d Y H:i:s.', filemtime($imagepath));


But you aren't going to get the date the pic was taken, just the date it was uploaded/modified. (unless it is a user entered field).

Also, there's no way you can get shutter speed in a jpg as its header informaiton doesn't contain it, jpg just doesn't care (nor should it) about that.

ionsurge
04-17-2003, 10:37 AM
Moving to php forum....

malcolm_macaula
04-17-2003, 06:16 PM
Thanks Feyd,

The jpeg format does seem to have some provision for header info as windows is able to display a whole list of attributes for jpegs I have taken, e.g. "Date Photo Taken", "Equipment Make".

I notice that jpeg's taken with a different camera have a different set of 'additional' attributes.

There must be a way to programmatically extract these as both XP and the Canon Zoombrowser software are able to display this info.

Thanks for PHP code - I can translate this into javascript which I use (+ XML, XSLT and batch jobs) to build my photo gallery site.

cheers

Malcolm

krycek
04-17-2003, 06:50 PM
You are correct.

JPEG files do have the ability to carry a lot of additional info. I'm not sure exactly how, or what the format is, but I will have a look and then post again. :)

::] krycek [::

krycek
04-17-2003, 06:53 PM
I thought I had seen some info a while back - here it is :D

http://search.cpan.org/author/GAAS/Image-Info-1.12/lib/Image/Info.pm

Quite a bit to read there!

::] krycek [::

Íkii
04-17-2003, 08:17 PM
if you have PHP4.3+ with GD2+ you can read/alter any of the iptc channeled information of any jpeg image very easily.

check the iptcparse and iptcembed functions of GD within the php.net manual for more information.

subnote: read exif data will return a small portion of the above , the exif functions will not allow writing or rewriting of the image information though.

http://www.php.net/manual/en/function.iptcparse.php
http://www.php.net/manual/en/function.iptcembed.php

malcolm_macaula
04-17-2003, 08:45 PM
Thanks a lot Feyd, krycek and Íkii.

This has helped me out greatly and hopefully I should be able to figure it out from here.

cheers

Malcolm

Feyd
04-19-2003, 06:52 AM
Some more informaiton for you on getting the EXIF information from a jpg...

http://www.zend.com/manual/function.exif-read-data.php

Billthemarmet
07-07-2003, 02:49 PM
You can use Pear if you are on win32 and dont want to recompile:

http://www.zonageek.com/software/php/jpeg/index.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum