How to read XYResolution Info on JPEG

Started by Archive, May 12, 2010, 08:53:50 AM

Previous topic - Next topic

Archive

[Originally posted by bubba on 2005-09-29 14:53:08-07]

Hi,

I'm at a loss now on how to read the X&Y Resolutions for the Display and Capture Headers using Perl can anyone please help me out with this. I'm nearly down to the wood on this one with all the head scratching I've done.

--
Thanks,

Bubba.

Archive

[Originally posted by exiftool on 2005-09-29 15:48:36-07]

Here is a sample perl script to extract XResolution and YResolution.  You need to place the script in the same directory as the ExifTool 'lib' directory, and run the script from there (unless you have done a full ExifTool install, in which case it will work if run from anywhere.)

I hope this is what you meant.

Code:
#!/usr/bin/perl -w

BEGIN { unshift @INC, 'lib'; }

use Image::ExifTool 'ImageInfo';

my $file = shift or die "must specify image file name\n";

my @tags = qw{ XResolution YResolution };
my $info = ImageInfo($file, @tags);

my $tag;
foreach $tag (@tags) {
    if ($$info{$tag}) {
        print "$tag = $$info{$tag}\n";
    } else {
        print "$tag not found\n";
    }
}

#end

Archive

[Originally posted by bubba on 2005-09-29 16:20:04-07]

Hi thanks for the reply, but using :
Code:
#!/usr/bin/perl -w
BEGIN { unshift @INC, 'lib'; }
use Image::ExifTool 'ImageInfo';
my $file = shift or die "must specify image file name\n";
my @tags = qw{ ImageHeight ImageWidth Compression NumberOfComponents BitsPerComponent DisplayResolution CaptureResolution };
my $info = ImageInfo($file, @tags);
my $tag;
foreach $tag (@tags) {
    if ($$info{$tag}) {
        print "$tag = $$info{$tag}\n";
    } else {
        print "$tag not found\n";
    }
}
#end

Produces as output:
Code:
# perl tester.pl 433C0F64.jpg
ImageHeight = 600
ImageWidth = 800
Compression not found
DisplayXResolution not found
DisplayYResolution not found

Even using the names listed in the http://search.cpan.org/~exiftool/Image-ExifTool-5.55/lib/Image/ExifTool/TagNames.pod#Jpeg2000_ImageHeader_Tags
documentation I still get nothing.

I guess I must be doing something wrong but I'm not to sure what yet. I'm working in the assumption here that if IrfanView can tell me these details then I guess exifTools should.

--
Bubba

Archive

[Originally posted by exiftool on 2005-09-29 17:43:54-07]

I thought the problem was that you wanted to know how to write the Perl code to extract this information.  If you don't care about writing the code yourself, using the provided 'exiftool' script is much simpler.

You can use 'exiftool' to see all of the information available in the image (just type "exiftool FILE", or use my favourite options and type "exiftool -a -u -G1 FILE".  The X/YResolution tags don't exist in all JPEG images.  If IrfanView reports them and exiftool doesn't, then IrfanView is probably just making them up.   Most software ignores the Resolution information and just displays the image according to the native screen resolution anyway.

Archive

[Originally posted by bubba on 2005-09-29 18:54:05-07]

Hello again,

It would appear that there is some confusion here. Originally I wanted to know how to write the Perl code so that I could extract the required parameters from the file, and because I was getting nothing back I assumed I my code was wrong. The sample Perl code (above) did this but did not, like mine, produce the results I expected based on my assumptions taken from IrfanView.

I am constructing a web service that needs to know the resolution of an image so I have an idea of the physical size of the image when printed. The images I have used for my tests have varying X and Y resolutions if IrfanView is to believed. With that said assuming these resolutions are estimated how would it (IrfanView) arrive at these resolutions, considering they range from 72 to 300? Is there some math I can do here?

For example an image of 800w x 600x and a resolution of 300x300 has an approximate printed size of 6.8cm x 5.1cm (assuming it's printed at 300 DPI).

I hope this clarifies what my intentions are and if I can be put in the right direction I'd very much appreciate that. Also, if I have totally lost the plot and I'm barking up the wrong tree I'd like to know that also.

--
Bubba

Archive

[Originally posted by exiftool on 2005-09-29 19:34:52-07]

OK great.  Now I understand what you want.  Thanks.

It would be useful if you could send me a sample image (send to philharvey66 at gmail.com) where IrfanView shows the resolution and exiftool does not.  I may be able to figure out what is going on.

Were these files written by IrfanView?  If so it is possible that there is some proprietary IrfanView-specific information included in the file.  Then ExifTool may not extract it.  Right now I can't think of any other possibility, but having a sample may help.

Archive

[Originally posted by exiftool on 2005-09-30 00:18:03-07]

Bubba,

Thanks for the sample.  Hey, you're right!  The resolutions are there in the file and not extracted by ExifTool.  They aren't in the EXIF information though, but in the JFIF APP0 segment (as XDensity, YDensity and DensityUnits).  Since ExifTool has already been expanded to read all sorts of other types of data, I don't see why it shouldn't read APP0 now too.  I will add this ability.

Thanks for pointing this out.

Archive

[Originally posted by exiftool on 2005-09-30 12:50:48-07]

I've added the ability to extract the resolution information and thumbnail image from the  JFIF APP0 segment.  This update will appear in version 5.64.  A 5.64 pre-release is available for download if you want to test it out before the official release is made (probably within a day or so).

Archive

[Originally posted by bubba on 2005-09-30 14:34:03-07]


I've installed the 5.64 version and it does what it says on the tin for the APP0 segment, however when this data isn't present (in what would appear to be digital camera images) I need to get the X & Y Resolutions from the IDF0 Group however it would appear this time that my Perl is b0rken.

This is what I'm using:
Code:
my $exifTool = new Image::ExifTool ;
my @ioTagList = ('ImageWidth', 'ImageHeight', 'XDensity', 'YDensity', 'FileSize', 'FileType', 'DateTimeOriginal', 'Compression', 'XResolution', 'YResolution', 'DensityUnits', 'ResolutionUnit') ;
my $info = $exifTool->ImageInfo($file, \@ioTagList) ;

Now when I submit an Image from a Digital Camera (Canon EOS 20D) I can extract the DateTimeOriginal, and Resesolution values. Submitting a Photoshop genererated image give me the XDensity and YDensity, so this proves that the approach I'm using to extract the info is correct and working! However, I still can't get a hold of the X and YResolutions.

I then intend to use :

Code:
$XRes = $info->{"XDensity"} = 0 ? $info->{"XResolution"} : $info->{"XDensity"} ;
$YRes = $info->{"YDensity"} = 0 ? $info->{"YResolution"} : $info->{"YDensity"} ;

So the web page could display the results regardless and I can do my math on the sizes. Could someone please point out where I'm going wrong?

--
Bubba

Archive

[Originally posted by exiftool on 2005-09-30 14:53:44-07]

Hi Bubba,

I have modified the pre-release to avoid some of this confusion by changing the names of the JFIF XDensity, YDensity and DensityUnits tags to be the same as the EXIF XResolution, YResolution and ResolutionUnits tags.  This should make things simpler for you because then you only have to look for the XResolution, YResolution and ResolutionUnits.

Give the new version a try and let me know if this helps.

Archive

[Originally posted by exiftool on 2005-09-30 14:56:37-07]

Oops.  That tag is called ResolutionUnit, not ResolutionUnits.  No "s".

Archive

[Originally posted by bubba on 2005-10-01 07:57:47-07]

Hi,

Having downloaded v5.64 everything is now working as I'd expected, thank you for all your time and effort it has been appreciated.

--
Bubba

Archive

[Originally posted by exiftool on 2005-10-02 00:27:01-07]

Any time.  Glad I could help.