shaq
shaq

Reputation: 187

How to retrieve height and width properties of a png file in perl

I have a link to a png file and I want to retrieve image properties like width and height. I have never done this before. I have take a look at GD but I could not find any method for resolving my issue.

here is an example of a png file

http://www.kegg.jp/kegg/pathway/map/map00010.png

Upvotes: 2

Views: 1535

Answers (3)

Slaven Rezic
Slaven Rezic

Reputation: 4581

Here's another example using the Image::Info module:

use LWP::Simple qw(get);
use Image::Info qw(image_info dim);
my $image_URL = "http://www.kegg.jp/kegg/pathway/map/map00010.png";
my $image_data = get($image_URL);
my($x, $y) = dim(image_info(\$image_data));
print "x is $x, y is $y\n"; 

Upvotes: 3

shaq
shaq

Reputation: 187

use Image::Size;

 my $image_URL="http://www.kegg.jp/kegg/pathway/map/map00010.png";
 my $pngfile="data.pang";
 getstore($image_URL,"$pngfile");         
 my($globe_x, $globe_y) = imgsize("$pngfile");
 print "x is $globe_x, y is $globe_y"; 

result is

x is 716, y is 1020

Upvotes: 3

caskey
caskey

Reputation: 12695

Using the Image::PNG::Libpng library you could:

 use LWP::Simple;
 my $image_data = get 'http://www.kegg.jp/kegg/pathway/map/map00010.png';
 my $png = create_read_struct();
 $png->read_from_scalar ($image_data);
 my $IHDR = $png->get_IHDR();
 print "Image size " . $IHDR{'width'} . " x " . $IHDR{'height'} . "\n";

Upvotes: 3

Related Questions