A cool resize / cropping script for creating thumbnails using mogrify
IMAGETEST.PHP
<?php
include 'mogrify.php';
$picture="sample.jpg";
$fixedwidth=300;
$fixedheight=240;
cropimage($picture,$fixedwidth,$fixedheight,$mogrify);
?>
MOGRIFY.PHP
<?php
$mogrify="C:/apache/Imagik/mogrify.exe";
function cropimage($picture,$fixedwidth,$fixedheight,$mogrify) {
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
if($width!=$fixedwidth){
$ratio =$fixedwidth/$width;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
$img = imagecreatefromjpeg($picture);
$width= imagesx($img);
$height= imagesy($img);
}
if($height!=$fixedheight){
$ratio =$fixedheight/$height;
$NewHeight=round($height*$ratio);
$NewWidth=round($width*$ratio);
exec( $mogrify." -resize ".$NewWidth."x".$NewHeight."! $picture");
exec( $mogrify." -crop ".$fixedwidth."x".$fixedheight."+0+0 $picture");
}
ImageDestroy($img);
}
?>
yeah!