well i know how to check the image size, i just want to actually resize that image to 640 x 480 if it's larger than 640 x 480. I have no idea how to resize an image and have been searching through php.net but i'm pretty confused.
I found a function at http://www.php.net/ImageCopyResized that seems like it might work for what I want to do. Can I just use this function how it is, and if so, how do I call the function (i'm not sure what all those parameters are).
Thanks
<?
ImageCopyResample(.....);
ImageJPEG(......);
function ImageCopyResample(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
global $resample; //submittet by querystring
$pxls = intval($src_w / $dst_w)-1;
if (($resample!="bicubic" && $pxls>=2) or $resample=="bilinear"){ //slow but better quality
ImagePaletteCopy ($dst_img, $src_img);
$rX = $src_w / $dst_w;
$rY = $src_h / $dst_h;
$nY = 0;
for ($y=$src_y; $y<$dst_h; $y++) {
$oY = $nY;
$nY = intval(($y + 1) * $rY+.5);
$nX = 0;
for ($x=$src_x; $x<$dst_w; $x++) {
$r = $g = $b = $a = 0;
$oX = $nX;
$nX = intval(($x + 1) * $rX+.5);
$c = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $nX, $nY));
$r += $c['red']; $g += $c['green']; $b += $c['blue']; $a++;
$c = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $nX-$pxls, $nY-$pxls));
$r += $c['red']; $g += $c['green']; $b += $c['blue']; $a++;
//you can add more pixels here! eg "$nX, $nY-$pxls" or "$nX-$pxls, $nY"
ImageSetPixel ($dst_img, ($x+$dst_x-$src_x), ($y+$dst_y-$src_y), ImageColorClosest ($dst_img, $r/$a, $g/$a, $b/$a));
}
}
return true;
} elseif ($resample=="bicubic"){ //very slow but better quality
ImagePaletteCopy ($dst_img, $src_img);
$rX = $src_w / $dst_w;
$rY = $src_h / $dst_h;
$nY = 0;
for ($y=$src_y; $y<$dst_h; $y++) {
$oY = $nY;
$nY = intval(($y + 1) * $rY+.5);
$nX = 0;
for ($x=$src_x; $x<$dst_w; $x++) {
$r = $g = $b = $a = 0;
$oX = $nX;
$nX = intval(($x + 1) * $rX+.5);
for ($i=$nY; --$i>=$oY;) {
for ($j=$nX; --$j>=$oX;) {
$c = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $j, $i));
$r += $c['red'];
$g += $c['green'];
$b += $c['blue'];
$a++;
}
}
ImageSetPixel ($dst_img, ($x+$dst_x-$src_x), ($y+$dst_y-$src_y), ImageColorClosest ($dst_img, $r/$a, $g/$a, $b/$a));
}
}
return true;
} else { //very fast!
$dst_w++; $dst_h++; //->no black border
return imagecopyresized($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}
}
?>
Cgraz