Subscribe to get design
tips, latest trends, free
stuff and more.
It doesn't look like an e-mail address


  Web Programming PHP Image Class: fly_resisze

Image Class: fly_resisze

nathanael PHP May 30, 2007

function fly_resize($source, $width, $height) {
$sourcefile = $source;
$imagesize = getimagesize("$sourcefile");
if($imagesize[0] > $width || $imagesize[1] > $width) {
if ($imagesize[0] > $imagesize[1]) {
$percentage = ($width / $imagesize[0]);
} else {
$percentage = ($height / $imagesize[1]);
$size = array();
$size[0] = round($imagesize[0] * $percentage);
$size[1] = round($imagesize[1] * $percentage);
return $size;

What this function does is figures out the correct proportions of an image, and returns those in an array of 2 keys; [0] being width and [1] being height.

You can use this if you want to resize an image, but not actually save that file. this is the same thing as taking a 1024x768 image, and doing <img src="./images/img.jpg" width="50" height="38">.

Here is a samle file showing the usage.

require_once 'func_images.php';

$obj_images = new images();

$resize = $obj_images->fly_resize("./test/Picture_1.jpg", "50", "50");
<img src="./test/Picture_1.jpg" width="$resize[0]" height="$resize[1]">



Well, thats all for the Image Class. Hopefully I comes in handy for you, I know it does for me :)

subscribe to newsletter