For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > Image::Magick speed issue









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Image::Magick speed issue
Jan Eden

2005-07-24, 8:29 pm

Hi,

I thought about using Image::Magick to create thumbnails for image gallerie=
s (either 10 or 5 thumbnails per page) on the fly and tested the following:

#!/usr/bin/perl

use strict;
use warnings;
use Image::Magick;
use CGI;

my $q =3D new CGI;
my %parameters =3D $q->Vars();

my $image =3D Image::Magick->new( );
$image->Read("../htdocs/bilder/$parameters{dir}/image/$parameters{file}");
my ($height, $width) =3D $image->Get('height', 'width');
$height =3D ($height > $width) ? 128 : 96;
$width =3D ($height =3D=3D 128) ? 96 : 128;
$image->Resize(height =3D> $height, width =3D> $width);

binmode STDOUT;
print $q->header( "image/jpeg" );
$image->Write("jpeg:-");

Unfortunately, this is unacceptably slow. I know that ImageMagick is quite =
ressource-intensive - but is there a way to significantly speed up the auto=
matic generation of thumbnails?

Thanks,

Jan
--=20
A good programmer is someone who looks both ways before crossing a one-way =
street. - Doug Linder
Zentara

2005-07-24, 8:29 pm

On Sun, 24 Jul 2005 11:22:18 +0200, lists@janeden.org (Jan Eden) wrote:

>Hi,
>
>I thought about using Image::Magick to create thumbnails for image galleries (either 10 or 5 thumbnails per page) on the fly and tested the following:
>
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>use Image::Magick;
>use CGI;
>
>my $q = new CGI;
>my %parameters = $q->Vars();
>
>my $image = Image::Magick->new( );
>$image->Read("../htdocs/bilder/$parameters{dir}/image/$parameters{file}");
>my ($height, $width) = $image->Get('height', 'width');
>$height = ($height > $width) ? 128 : 96;
>$width = ($height == 128) ? 96 : 128;
>$image->Resize(height => $height, width => $width);
>
>binmode STDOUT;
>print $q->header( "image/jpeg" );
>$image->Write("jpeg:-");
>
>Unfortunately, this is unacceptably slow. I know that ImageMagick is quite ressource-intensive - but is there a way to significantly speed up the automatic generation of thumbnails?


I think you ought to generate them once, and store them in some sub-dir.
You could setup a way of testing if the thumbnail exists, if it does
link to it, if not generate it, then link to it. That way it will only
be slow the "first time".



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Jan Eden

2005-07-24, 8:29 pm

Hi,

zentara wrote on 24.07.2005:

>On Sun, 24 Jul 2005 11:22:18 +0200, lists@janeden.org (Jan Eden)
>wrote:
>
=2E..[color=darkred]
>
>I think you ought to generate them once, and store them in some
>sub-dir. You could setup a way of testing if the thumbnail exists, if
>it does link to it, if not generate it, then link to it. That way it
>will only be slow the "first time".


The idea is to save disk space, as there are quite a lot of pictures to be =
organized in the galleries. My current setup works similar to what you prop=
osed, except that I create thumbnails for each new gallery at once (on my l=
ocal server, prior to uploading).

With your solution, the script would need write access for the thumbnail di=
rectory actual webserver which I would like to avoid.

But I will think about a possible solution in the light of your recommendat=
ion again.

Many thanks,

Jan
--=20
No trees were killed in the creation of this message. However, many electro=
ns were terribly inconvenienced.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com