简体   繁体   中英

Resize uploaded image to max width, max height?

i have a php image upload upload form and what i want to do is before the image is saved on my server, it needs to be resized to make sure the height doesnt exceed the max height ive set, and the width doesnt exceed the max width i set. I was thinking the way to do it would first be a) check if the width is greater than max width. If so, PROPORTIONALLY resize image so the width equals the max width. Then, check the height. If the height exceeds max height, proportionally resize the image so the height equals the max height.

Any suggestions? GD is installed on my server..

Assume that the image is echo $_FILES["file"]["name"];

Using gd is as lightweight as it's going to get. The idea that you're going to resize images without using a library is basically just humorous.

I've answered a similar question to what you are asking:

Resize images with PHP

It uses GD b/c like chaos says, it doesn't get any more lightweight.

This script resizes an image on demand, but caches each size of each image that has ever been called so that it doesn't have to be resized again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM