我想在固定尺寸为400 * 400的正方形内显示图像。因此,要保持长宽比,可能的是,如果宽度更大,则宽度会减小,并且按照长宽比的剩余空间将被一些填充背景颜色(我可以在div上指定颜色)。类似地,如果高度更大,则将调整高度以按照纵横比显示它,然后剩余空间将被背景填充。
有人可以帮我实现这一目标吗?可以用imagemagick完成吗?
http://php.net/manual/en/book.imagick.php
任何帮助,将不胜感激。
最佳答案
使用phpthumb。
require_once '/path/to/ThumbLib.inc.php';
$thumb = PhpThumbFactory::create('path/to/image.jpg');
//$thumb->resize(400, 400);
// resize image and make thumbnail by cropping image automatically
$thumb->adaptiveResize(400, 400)->save('/path/to/thumb.jpg'); ;
有关更多阅读,请转到PHPTHUMB