Jump to content

Resize image with same aspect ratio


Vivid Lust

Recommended Posts

html has an image resize tag

 

Which is almost certainly a bad way to do it. If you use a big image and "resize" it with the img tag's attributes, then it'll still use just as much bandwidth as the big image and still take just as long to load.

 

Vivid Lust, why don't you want to use getImageSize()?

Link to comment
Share on other sites

Oh, which keeps the original aspect ratio if there is a limit of 200px on the width? I don't think there is  :(

 

Yes there is, you just set height = height * (200/originalWidth). It's basic mathematics. You find the relative growth of the width and multiply the height with that same growth rate. Doing that you'll retain the proportions. As GingerRobot said, you still shouldn't use HTML attributes for image resizing though.

Link to comment
Share on other sites

You should not be using a URL with getImageSize() when the file is on your own server and if the file is in a database and you are manipulating it using GD functions, you can get the size using other GD functions than getImageSize().

 

How are you using getImageSize()? What is your actual code?

Link to comment
Share on other sites

Hi,

 

I have image URL's stored in the database and want to resize them so they fit into the div width of X and so that they mantain their original aspect ratio.

 

My first step would be:

 

GetImageSize($image);

 

where $image is the current URL from the database. However my host does not allow this.

 

Jake.

Link to comment
Share on other sites

If you figure out some way to get the original dimensions of the image you could use something like this to scale it down:

 

function get_new_dimensions($image)
{
$size = getimagesize($image);
list($width, $height) = $size;
while($width > 130 || $height > 130)
{
	$width *= .9;
	$height *= .9;
}
$new_size = array($width, $height);
return $new_size;
}

Just change the 130's to the max width and height of the resized image.

 

Edit: That's only to get the new dimensions, of course. Then you'd have to create a new image with those aspects.

Link to comment
Share on other sites

Not to sound like an ass but getting free "Unmetered" hosting isnt going to sovle your problem as Daniel said you will need seomthing that you can atleast control its configuration, E.G Vps Server personally i like my Dedi's but shared hosting is not going to pay off in the long run if another users site goes down for any reason you may suffer from that, so be smart and take a VPS atleast :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.