简体   繁体   中英

php resize thumbnail to fixed dimensions - no crop

I want to resize an image to a fixed size of 400x300.

I do not want to zoom crop it, I simply want the image constrained to either the width 400 or height 300 (depending on orientation), the image centered, and the rest of the image filled with black.

Does anyone know of a library/code that does this? (for GD)

Thanks, Wesley

GD or ImageMagick can easily do this for you.

Create a new image with a black background of the desired height, then copy from the original, and place in the new .

Perhaps another answer will come along with the full code, but this will get you started. If not, I will post code for you later.

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