用比例调整图像大小?
我正在使用这个功能
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 宽度而不变形。
有谁知道该怎么做?
I am using this function
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;
}
What I want to do is make a square image. I would like to resize by the smallest attribute, then instead of the larger number being squished. I would like the edges chopped off.
So if I have an image which is 213 x 180 which I need resized to 150 x 150
I can resize the image to 150 height before it hits this function.
What I don't know how to do is take the width and chop off the edges to get 150 width without distortion.
Does anyone know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你所说的“砍掉”边缘是指剪掉你的图像,对吧?
要裁剪图像,您可以使用 imagecopyresized。
一个小例子:
By "Chop off" the edge i guess you mean making a crop of you're image, right ?
For croping a image you could use imagecopyresized.
A little example :
这是从我的一个旧项目复制的,可以满足您的需要:
This is copied from an old project of mine, does what you need: