Gossamer Forum
Home : Products : DBMan : Customization :

Image Magick Thumbnail creation

Quote Reply
Image Magick Thumbnail creation
Hi, im using the file upload 3. I searched already for image magic and didn't quite find what i was looking for. I want to auto generate thumbnails with image magick with the upload mod. I looked at the faq section but did not find anything with images. could someone point me in the right direction, or help me add that line to generate the new image. The code to generate the thumbnails is this:

convert originalfile.jpg -quality 55 -geometry 100x100 originafile-thumbnail.jpg



thanks!
Quote Reply
Re: [ryans] Image Magick Thumbnail creation In reply to
I can't help you really with what you are asking exactly, however, I can show you how I use it, maybe that helps:

[code]

my $original;
# -----------------------------------------------------------------
# hardcode to pass in via cgi in real code

$original = $file;
($val1, $val2) = split(/\./, $original);

my $valtn = $val1. "_th" ;
my $valnrm = $val1. "" ;
my $FNThum = ("$valtn.$val2");
my $FNFull = ("$valnrm.$val2");

my $FileNameIn = $build_photo_path_temp . '/' . $file ;
my $FileNameFull = $build_photo_path . '/' . $FNFull ;
my $FileNameThum = $build_photo_path . '/' . $FNThum ;

# hardcoded paramters to require via config file in real code

my ( $MaxFullimgX , $MaxFullimgY ) = (200,200);
my ( $MaxThumimgX , $MaxThumimgY ) = (75,75);
my $ImageQuality = 80 ; # value 10-90
my $AnnotateFont = '@Comic.ttf' ;
my $AnnotatePointsize = 10 ;
my $AnnotateText = '' ;

# ---------------------------------------------------------
# local var declarations

my $image ;
my ( $imgX , $imgY ) = (0,0);
my ( $ratioX , $ratioY ) = (0.0,0.0);

# -------------------------------- executable ---------------

( $imgX , $imgY ) = $image->Get('columns', 'rows');

# figure out re-sample parameters, keeping aspect ratio for Full-size image
# -----

if ($imgX >= $MaxFullimgX || $imgY >= $MaxFullimgY) {
$ratioX = $MaxFullimgX / $imgX ;
$ratioY = $MaxFullimgY / $imgY ;
if ( $ratioX < $ratioY ) { # use the smaller ratio
( $imgX , $imgY ) = ( $imgX * $ratioX , $imgY * $ratioX ) ;
} else { ( $imgX , $imgY ) = ( $imgX * $ratioY , $imgY * $ratioY ) ;
}
$image->Resize(width=>$imgX , height=>$imgY, blur=>0.5, filter=>Box ); # re-size the image
}

if ( $AnnotateText ) {
$image->Annotate( text=>$AnnotateText ,
font=>$AnnotateFont ,
pointsize=>$AnnotatePointsize );
}

$image->Write( filename=>$FileNameFull , quality=>$ImageQuality );

# figure out re-sample parameters, keeping aspect ratio for thumbnail image
# -----
$ratioX = $MaxThumimgX / $imgX ;
$ratioY = $MaxThumimgY / $imgY ;
if ( $ratioX < $ratioY ) { # use the smaller ratio
( $imgX , $imgY ) = ( $imgX * $ratioX , $imgY * $ratioX ) ;
} else { ( $imgX , $imgY ) = ( $imgX * $ratioY , $imgY * $ratioY ) ;
}
# $image->Sample(width=>$imgX , height=>$imgY );
$image->Resize(width=>$imgX , height=>$imgY, blur=>0.5, filter=>Box ); # re-size the image

$image->Write( filename=>$FileNameThum , quality=>$ImageQuality );

undef $image; # release memory

[/code]

As you can see, I had my uploaded image at:
$build_photo_path_temp
and created a 200 x 200 (max size) and a 75 x 75 image from that with image magick.

Hope this might help.

Lex
Quote Reply
Re: Image Magick and DBMan In reply to
I know it's been a while since anybody posted in this thread, but I was wondering if anyone can give me a hand with using Image Magick (it's installed on my server).

I'm using the multiple upload MOD (which works great!) and I want to resize my uploaded images to a specific size (let's say 330x240).
How can I do this with DBMan and ImageMagick?

Does anyone know?

Thanks!