Hi all, I'm having a probblem with a GD resize / crop script and i'm wondering if anyone can help me.
The code is supposed to take an uploaded image, resize it to the correct width (532px), retaining its aspect ration, and then crop it (to 532 x 100). Currently it crops it fine and it's doing some resizing but it's ignoring the dimensions i'm asking for and just shrinking it a little bit, it's also distorting the image...
Can anyone see what's wrong?
$rWidth = 532;
$rHeight = 100;
$name = ( $_FILES['userfile']['name'] );
if ($name){
$target_path = "../../images/page_images/";
$target_path = $target_path . basename( $_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path);
$dimensions = getimagesize($target_path);
if ($dimensions[0] != $rWidth && $dimensions[1] != $rHeight){
$canvas = imagecreatetruecolor($rWidth,$rHeight);
$piece = imagecreatefromjpeg($target_path);
$width = $dimensions[0];
$height = $dimensions[1];
$newWidth = $rWidth;
$newHeight = round($rWidth/($width/$height));
imagecopyresized($canvas, $piece, 0, 0, 0, 0, $rWidth, $rHeight, $newWidth, $newHeight);
imagejpeg($canvas,$target_path,90);
}
}
Thanks in advance for your help.
Silas