Image Magick finding image size without loading image 
Author Message
 Image Magick finding image size without loading image
I am using perl and Image::Magick to automatically enter
image height and width into my html code.  Is there a way to determine
the image size without loading the image using $image->Read()?
Since I only want the image size information, I do not want
my code to be slowed down by loading entire images.  Or, is
Image::Magick smart enough not to load the actual image if
the image data is not used?  If anyone knows a way to quickly
get image size information in perl, their help would be appreciated.
I do not necessarilly need to use Image::Magick for this purpose.

Thanks, Peter Andrews



Mon, 09 Aug 2004 02:32:45 GMT  
 Image Magick finding image size without loading image
You can use Image::Size

use Image::Size;
($x,$y) = imgsize("image.gif");
($x,$y) = imgsize("image.jpg");

http://search.cpan.org/search?dist=Image-Size

Marco Gazerro

Quote:

> I am using perl and Image::Magick to automatically enter
> image height and width into my html code.  Is there a way to determine
> the image size without loading the image using $image->Read()?
> Since I only want the image size information, I do not want
> my code to be slowed down by loading entire images.  Or, is
> Image::Magick smart enough not to load the actual image if
> the image data is not used?  If anyone knows a way to quickly
> get image size information in perl, their help would be appreciated.
> I do not necessarilly need to use Image::Magick for this purpose.

> Thanks, Peter Andrews



Mon, 09 Aug 2004 03:25:06 GMT  
 Image Magick finding image size without loading image
The find(1) program on Unix will tell you the size of many common
image formats.  Perhaps not JPEG, but the cjpeg/djpeg/etc set of tools
might come with something for that.

--

Finger for PGP key



Mon, 09 Aug 2004 04:59:21 GMT  
 Image Magick finding image size without loading image
On 20 Feb 2002 10:32:45 -0800,

Quote:
> I am using perl and Image::Magick to automatically enter
> image height and width into my html code.  Is there a way to determine
> the image size without loading the image using $image->Read()?

Image::Magick::Ping();

($width, $height, $size, $format) = $IM_object->Ping('logo.png');

or

($width, $height, $size, $format) = Image::Magick->Ping('logo.png');

See the documentation for Image::Magick. If you don't have it
installed, see: http://www.imagemagick.org/www/perl.html

Quote:
> I do not necessarilly need to use Image::Magick for this purpose.

If you have a need for speed, and you don't need to do anything bu get
image sizes, then I suggest that Image::Size would be a better
solution for this. It reads fewer formats than Image::Magick, but I
doubt that that would be a problem.

Martien
--
                                |
Martien Verbruggen              | That's funny, that plane's dustin'
Trading Post Australia Pty Ltd  | crops where there ain't no crops.
                                |



Mon, 09 Aug 2004 06:34:06 GMT  
 Image Magick finding image size without loading image

Thanks Marco!
It worked like a dream, and greatly increased my program speed
as compared with Image::Magick.
Peter Andrews

Quote:
> You can use Image::Size

> use Image::Size;
> ($x,$y) = imgsize("image.gif");
> ($x,$y) = imgsize("image.jpg");

> http://search.cpan.org/search?dist=Image-Size

> Marco Gazerro


> > I am using perl and Image::Magick to automatically enter
> > image height and width into my html code.  Is there a way to determine
> > the image size without loading the image using $image->Read()?
> > Since I only want the image size information, I do not want
> > my code to be slowed down by loading entire images.  Or, is
> > Image::Magick smart enough not to load the actual image if
> > the image data is not used?  If anyone knows a way to quickly
> > get image size information in perl, their help would be appreciated.
> > I do not necessarilly need to use Image::Magick for this purpose.

> > Thanks, Peter Andrews



Mon, 09 Aug 2004 06:34:18 GMT  
 Image Magick finding image size without loading image

Edward> The find(1) program on Unix will tell you the size of many common
Edward> image formats.

Not standard Unix.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Mon, 09 Aug 2004 08:10:04 GMT  
 Image Magick finding image size without loading image

Quote:
>Edward> The find(1) program on Unix will tell you the size of many common
>Edward> image formats.

>Not standard Unix.

Definitely not since as Mike Stok pointed out to me, I meant file(1)
not find(1) :-).

But perl isn't standard Unix either - wouldn't stop me recommending it
as the answer to a problem.  Besides I said Unix not UNIX(tm).

--

Finger for PGP key



Mon, 09 Aug 2004 18:00:30 GMT  
 Image Magick finding image size without loading image

Quote:

>I am using perl and Image::Magick to automatically enter
>image height and width into my html code.  Is there a way to determine
>the image size without loading the image using $image->Read()?

Yeah... By not using Image::Magick. The module Image::Size will do it
for many file types.

--
        Bart.



Mon, 09 Aug 2004 18:59:17 GMT  
 Image Magick finding image size without loading image
On Thu, 21 Feb 2002 10:59:17 GMT,

Quote:

>>I am using perl and Image::Magick to automatically enter
>>image height and width into my html code.  Is there a way to determine
>>the image size without loading the image using $image->Read()?

> Yeah... By not using Image::Magick. The module Image::Size will do it
> for many file types.

This is misleading. See also another one of my posts in this thread.

Image::Magick is perfectly capable of giving you the pixel size of an
image stored in a file, without reading the file, and it can do so for a
much larger range of image formats than Image::Size.  However,
Image::Size is much smaller and lighter, and cheaper to load.

If all you need is image sizes of one of the most commonly used image
formats, Image::Size is the way to go. If you, in the same program, need
to also manipulate images, there is no reason to also load Image::Size,
and you can simply use Image::Magick to do all the work. Other reasons
to use Image::Magick: If you're not worried about performance as much,
and you expect image formats that Image::Size doesn't handle.

Martien
--
                        |
Martien Verbruggen      | I took an IQ test and the results were
                        | negative.
                        |



Mon, 09 Aug 2004 19:18:43 GMT  
 Image Magick finding image size without loading image
Thanks for all your help, especially Martien.  Problem solved already.
Image::Size is working fine, and I'll switch to Image::Magick::Ping
as soon as is convenient.  Somehow I missed Ping in my reading of
Image::magick documentation, which led to this thread.  I found it in the
documentation a few days ago, and am happy to see that Martien found the
best solution as well.

  -Peter Andrews



Tue, 17 Aug 2004 05:40:10 GMT  
 Image Magick finding image size without loading image

Peter> Somehow I missed Ping in my reading of Image::magick
Peter> documentation, which led to this thread.

Many people miss many things in the Image::Magick docs, because it's
not all there. :(

print "Just another Perl hacker,"

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Tue, 17 Aug 2004 06:44:55 GMT  
 Image Magick finding image size without loading image
On 28 Feb 2002 14:44:55 -0800,

Quote:

>Peter> Somehow I missed Ping in my reading of Image::magick
>Peter> documentation, which led to this thread.

> Many people miss many things in the Image::Magick docs, because it's
> not all there. :(

No, it isn't all there, and what is there is a bit terse. It helps to
also read the documentation for the command line tools, since the Perl
API most closely resembles the command line options for those tools.
Furthermore, the ImageMagick toolset and its APIs change quite a bit,
so keeping all the documentation totally up to scratch is quite some
work.

There have been some initial moves to get a book about ImageMagick
started, but from what I heard John Cristy himself didn't really have
the time to write it, and the last I heard about it was quite some
time ago, so I don't know what's happening with that.

Martien
--
                        |
Martien Verbruggen      | I'm just very selective about what I accept
Trading Post Australia  | as reality - Calvin
                        |



Tue, 17 Aug 2004 07:06:29 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Converting images without Image::Magick

2. Image::Magick: find the last image read

3. Image::Magick: find the last image read

4. Can't load Magick.so for module Image::Magick

5. Merging and splitting of images with Image::Magick

6. convert jpg-images to tiff format with image-magick on winnt

7. Image Magick and returning images to a web page

8. AS Perl 629 Image::Magick makes Perl crash when outputting image to file

9. Image::Magick making images from layers

10. ANNOUNCE: Tutorial # 32: Showcasing Image::Magick (part 2): xml-2-image.pl

11. ANNOUNCE: Tutorial # 31: Showcasing Image::Magick (part 1): text-2-image.pl

12. CGI image generation using Image::Magick

 

 
Powered by phpBB® Forum Software