尝试调整缩略图的大小和裁剪图像


Trying to resize and crop image for thumbnail

我要做的是调整上传图像的中心大小和裁剪。到目前为止,我已经把它调整到调整图像大小的地方,仅此而已。我知道图像复制功能是我想要的,我只是无法让它与我的函数一起使用。

这就是我目前所拥有的。

/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width  */
$desired_height = floor($height*($desired_width/$width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width,$desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image,$dest);

我只需要知道在哪里以及如何合并图像复制功能。

谢谢。

看看这个类。它包含 GD2,如您提供的示例,它还具有用于缩略图生成的其他调整大小算法。

这是我

使用imagemagick/php编写的一个函数来做到这一点:

stackoverflow.com/questions/20927238