我正在使用这个功能
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagesavealpha($new_image, true);
$trans_colour = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
imagefill($new_image, 0, 0, $trans_colour);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
我想做的是制作一个方形图像。我想按最小的属性调整大小,而不是压缩较大的数字。我想要把边缘切掉。
因此,如果我有一个 213 x 180 的图像,我需要将其大小调整为 150 x 150
在调用此函数之前,我可以将图像大小调整为 150 高度。
我不知道该怎么做,就是获取宽度并砍掉边缘以获得 150 宽度而不变形。
有人知道怎么做吗?
最佳答案
通过“砍掉”边缘,我猜你的意思是剪掉你的图像,对吗?
要裁剪图像,您可以使用 imagecopyresized .
一个小例子:
$imageSrc = //Your source image;
$tempImage = imagecreatetruecolor(150,150);
// CropStartX et cropStartY have to be computed to suit your needs
imagecopyresized($tempImage,$imageSrc,0,0,$cropStartX,$cropStartY,150,150,150,150);
// $tempImage now contain your cropped image.
关于php - 用比例调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5309682/