• You are not logged in. | Login

Post a reply

November 17, 2006 6:32 am

mdwb
Member
Ranks

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
Ranks

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

 

 
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services