Script php dibawah ini bisa digunakan untuk meresize ukuran gambar otomatis dan mengubah resolusinya.

<?php
$imagefile=$_FILES[‘img’][‘tmp_name’];
$imgname=$_POST[‘imgname’];
$resolution=72;
$maxwidth=600;
function imgcompress($maxwidth, $resolution, $imgname, $imagefile){
if($w>=$maxwidth){
$persen=($w-$maxwidth)/$w;
$w_b=$w-$maxwidth;
$w_baru=$w-$w_b;
$h_b=($h*$persen);
$h_baru=$h-$h_b;
$image=imagecreatetruecolor($w_baru,$h_baru);
$src=imagecreatefromjpeg($imagefile);
imagecopyresampled($image,$src,0,0,0,0,$w_baru,$h_baru,$w,$h);
imagejpeg($image,’images/’.$imgname,$resolution);
imagedestroy($image);
imagedestroy($src);
}else{
$image=imagecreatetruecolor($w,$h);
$src=imagecreatefromjpeg($imagefile);
imagecopyresampled($image,$src,0,0,0,0,$w,$h,$w,$h);
imagejpeg($image,’images/’.$imgname,$resolution);
imagedestroy($image);
imagedestroy($src);
}
}
?>

(Visited 1,965 times, 3 visits today)