Jump to content

Fitting every image into a "standard size"


Fenhopi

Recommended Posts

As you stated, why don't you simply set a max-width or max-height for the images. This will also maintain the resolution of the images as opposed to forcing them to a certain width or height

eh?

 

Lets say that you want all the uploaded pictures to have a max height of 300px and a max width of 200px. Any images that users upload which are smaller than these dimensions are going to look stupid, however you can check the image size using the following function:

 

http://uk3.php.net/get_image_size

 

If the image is smaller than you require, you could send a message to the user and simply delete the image from the server. If the image is accepted then you need to use a graphics library to rescale/resize the image to the appropriate dimesions. Based on the orientation of the image it will either have a max height of 300px or a max width of 200px (landscape). Or, you may want a fixed size of 300x200 so therefore you will need to crop the image.

 

You can use php's GD library to perform these operations http://uk3.php.net/manual/en/ref.image.php There are plenty of tutorials available. I would personally recommend installing Image Magic on your server as this is much more powerful. http://www.imagemagick.org/script/index.php Again there are loads of tutorials out there.

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.