Fenhopi Posted June 23, 2011 Share Posted June 23, 2011 Hi, my website allows users to upload pictures. But when I display these pictures I need them all to not be larger than a certain max width and height.. Is it some tutorial on how to fit images proportionately? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/240260-fitting-every-image-into-a-standard-size/ Share on other sites More sharing options...
fugix Posted June 23, 2011 Share Posted June 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240260-fitting-every-image-into-a-standard-size/#findComment-1234099 Share on other sites More sharing options...
JonnoTheDev Posted June 24, 2011 Share Posted June 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240260-fitting-every-image-into-a-standard-size/#findComment-1234227 Share on other sites More sharing options...
EdwinPaul Posted June 24, 2011 Share Posted June 24, 2011 Look at topic http://www.phpfreaks.com/forums/index.php?topic=336990.0 Image resize: http://www.bitrepository.com/web-programming/php/resizing-an-image.html Quote Link to comment https://forums.phpfreaks.com/topic/240260-fitting-every-image-into-a-standard-size/#findComment-1234231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.