Rated an average of 4 stars by 3 people

Resize Image

Script Details:
Added on March 14, 2009 by Speedy. Last modified March 15, 2009.
Speedy accreditted the script to himself.

Description:
This script scales the image correctly according to it's original width and height.

Tags: function, height, image, resize, scaling, width

Instructions:
This function returns an array and you can use it like this:
$resize = ResizeImage(file,maxwidth,maxheight);
$resize['height'] contains the new height
$resize['width'] contains the new width

Code:

<?php
# Snippet from PHP Share: http://www.phpshare.org

function ResizeImage($file$width$height)
{
    list(
$orgwidth$orgheight) = getimagesize($file);
    
    
$orgratio $orgwidth $orgheight;

    if (
$width $height $orgratio)
    {
        
$width $height $orgratio;
    }
    else
    {
        
$height $width $orgratio;
    }
    
    return array(
'width'=> $width'height'=> $height);
}
?>

Review this PHP Script:

Rating:

Comments:


Login

User:
Pass:

Register

Not a member? Register today and receive the many free benefits of being a member!

Advertisements