
- You are not logged in. | Login
November 17, 2006 6:32 am
- mdwb
- Member


help with resizing uploaded image
Hi, I'm looking for some way to resize an uploaded image before saving it using PHP.
Don't be afraid of life, it is yours!
November 17, 2006 6:31 pm
- phppat
- Member


Re: help with resizing uploaded image
PHP usually comes bundles with the GD library, a set of image manipulation functions.
You can tell if it's installed on your environment with this function:
<?php phpinfo(); ?>
Try looking for the section titled 'gd', and make sure the next like is 'GD Support: enabled'. You'll also see what image formats are supported here.
Then you can use code like this bit from the php manual:
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>PHP monster


