Gossamer Forum
Home : Products : DBMan : Customization :

Image manipulation

Quote Reply
Image manipulation
I have the multiple upload mod working on my website, but I'd like to be able to have the script resize pictures using image magick or image size. My host has both installed on the servers, so that part of it should be ok.

It's been my experience that most people that post their pictures don't seem to know how to resize them, so I'm looking for a way to have the script do it. For example, a picture coming in at 640x480 would be resized to 500x* etc. Would there be a way to do that without resizing a picture that's 400x300 up to 500x*? If that's possible, how would I do that?
Thanks a bunch!


DBMan SQL Version 1 mods available at:
http://dbmansqlmods.rainbowroomies.com
(Mods based on JPDeni's original mods.)
Quote Reply
Re: [shann123] Image manipulation In reply to
I do it like this:

[code]
sub image_resize {

use Image::Magick;
use CGI;
$in = new CGI;
$file = $Filename;

my $build_photo_path = "/hsphere/local/home/govert/allesoversterrenkunde.nl/fotos";

# $build_photo_path\/

my $original;
# -----------------------------------------------------------------

$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 ;

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 ---------------

$image=Image::Magick->new;
$image->Read( $FileNameIn );

( $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

return;

}
[/code]

Hope this helps. (I now it's a bit late...)
Quote Reply
Re: [Lex] Image manipulation In reply to
Hi Lex,
Thanks for the reply! I still haven't worked on this for a while, but it was still something I needed. I'm not sure how to implement this into the website. I see where I'd change the values as far as the directory and sizes, but what do I need to do to tie this in with the upload sub routine?

Thanks again!


DBMan SQL Version 1 mods available at:
http://dbmansqlmods.rainbowroomies.com
(Mods based on JPDeni's original mods.)