I’ve been trying to mess with GD to resize an image to fit an 800×600 resolution. I used an online tutorial I found, [url]http://www.phptutorial.info/learn/create_images/#code8[URL=”http://img71.imageshack.us/img71/4436/51200925424pmes9.jpg”]this image[URL=”http://img380.imageshack.us/img380/5425/1112hz8.jpg”]this one
What am I doing wrong? Here’s the entire page code.
[code=php]<?php print_r($_FILES); echo ‘<br /><br />’;
if ($_FILES[‘avatar’][‘type’] != ‘image/jpeg’) echo ‘Wrong file format’;
$img[‘old’] = imagecreatefromjpeg($_FILES[‘avatar’][‘tmp_name’]);
$img[‘info’] = getimagesize($_FILES[‘avatar’][‘tmp_name’]);
print_r($img[‘info’]); echo ‘<br /><br />’;
$img[‘width’] = $img[‘info’][0];
$img[‘height’] = $img[‘info’][1];
$ratio = ($img[‘width’] > 800) ? (800 / $img[‘width’]) : 1;
$img[‘new_width’] = $img[‘width’] * $ratio;
$img[‘new_height’] = $img[‘height’] * $ratio;
$img[‘new’] = imagecreate($img[‘new_width’], $img[‘new_height’]);
imagecopyresized($img[‘new’], $img[‘old’], 0, 0, 0, 0, $img[‘new_width’], $img[‘new_height’], $img[‘width’], $img[‘height’]);
imagejpeg($img[‘new’], ‘uploads/111.jpg’, 100);
imagedestroy($img[‘new’]);
print_r($img);
?>
<img src=”<?=setting(‘absolute’);?>/uploads/111.jpg” />
<form method=”post” enctype=”multipart/form-data”>
<h2>Upload an avatar</h2>
<input type=”file” name=”avatar” /><br />
<input type=”submit” value=”Done” />
</form>