Reply to Re: how to choose the correct height/width for images

Your name:

Reply:


Posted by VS on 02/03/07 22:01

Sounds like you need to re-size the image based on Width / Height Ratio
between the original image and your maximum desired size. I've not done
Image re-sizing in PHP, but you might be able to devise your own based
on this bit of Perl that I used:

# CreateThumbnail(Source, Destination)
sub CreateThumbnail
{
my( $src_file, $dst_file) = @_;

my $quality = 100;
my $newwidth = 160;
my $newheight = 120;

# create a new image from original
$im = GD::Image->newFromJpeg($src_file);
($width, $height) = $im->getBounds();

# Width / Height Ratio's
$wr = $width / $newwidth;
$hr = $height / $newheight;

if ($wr > $hr){
$newheight = int(($height / $wr)+0.5);
$newwidth = int(($width / $wr)+0.5);
}else{
$newheight = int(($height / $hr)+0.5);
$newwidth = int(($width / $hr)+0.5);
}

# new image for re-sized / re-sampled version
$outim = new GD::Image($newwidth, $newheight);
$outim->copyResized($im, 0, 0, 0, 0, $newwidth, $newheight,
$width, $height);
$outim->interlaced('true');

# Put a black frame around the Image
$black = $outim->colorAllocate(0,0,0);
$outim->rectangle(0,0,$newwidth-1,$newheight-1,$black);

#save the new Image...
open(DST , '>', "$dst_file") || die "could not write image: $!";
binmode DST;
print DST ($outim->jpeg($quality));
close(DST);
}

--
VS

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация