Image Help (noob)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Image Help (noob)

Post by Foxy999 »

Is it possible to scale/re-size an image as it is being printed on a page? I want to do this instead of resizing the image then storing it on my server.

Also is it possible to return the dimensions of an image?

Foxyy
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Image Help (noob)

Post by aceconcepts »

You can use something like this:

Code: Select all

 
function resize_image($filename, $new_width)
{
    $img_size = getimagesize("images/photos/".$filename); //get the original image size
    $width=$img_size[0]; //get original image width
    $height=$img_size[1]; //get original image height
    
    $new_width=150;
    $new_height=floor(($height/$width)*$new_width);
    
    $dimensions=array($new_width, $new_height); //create array of new dimensions
    
    return $dimensions;
}
 
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Image Help (noob)

Post by Foxy999 »

I think that will work for getting the dimensions of a scaled image, and the dimensions or the original image, but it doesn't create an image with the new dimensions.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Image Help (noob)

Post by aceconcepts »

Apologies, I read your original post as attempting to "scale/resize animage".
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Image Help (noob)

Post by Foxy999 »

I want to know if it is able to scale it on the page, without creating a new image.

Also, does that code even re-size the image? It seems like it only create new dimensions that are to scale, but then again I don't know too much about php.
Post Reply