Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Chicago
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question extracting attributes from jpeg file

    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

  • #2
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    403
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    $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.
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    A 4D universe
    Posts
    1,337
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Moving to php forum....
    http://www.mudsplat.com - Web design, print, and marketing solutions.

  • #4
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Chicago
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought I had seen some info a while back - here it is

    http://search.cpan.org/author/GAAS/I.../Image/Info.pm

    Quite a bit to read there!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #8
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Chicago
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    403
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Some more informaiton for you on getting the EXIF information from a jpg...

    http://www.zend.com/manual/function.exif-read-data.php
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #10
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Alberta
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pear

    You can use Pear if you are on win32 and dont want to recompile:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •