为什么我的图像在裁剪时会拉伸?
我正在使用以下代码片段来裁剪图像?
function crop($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $width, $height );
$this->image = $new_image;
}
这里,$this->image
是原始图像$this->getWidth()
和$this->getHeight()
保存图片的原始尺寸,其中 $width
和 $height
是裁剪区域。
但由于某种原因,裁剪图像被调整了大小(我们几乎可以说它被调整了大小)。
如何解决这个问题?
I am using the following code snippet in order to crop a image?
function crop($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $width, $height );
$this->image = $new_image;
}
Here, $this->image
is the original image $this->getWidth()
and $this->getHeight()
holds the original dimensions of the picture, where as $width
and $height
, is the crop area.
But for some reason, the crop image is resized(we can almost say it is resized).
How to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,问题在于给出源尺寸。给出整个图像的尺寸将调整大小而不是裁剪。
这应该可以解决问题
Well, the problem is giving the source dimensions. Giving the dimensions of entire image will re size instead of cropping.
This should solve the problem
是的,我有一个无需淀粉即可裁剪上传图像并调整大小的解决方案
请按照以下步骤操作:
第 1 步:创建一个新的 index.php 文件。
步骤 2:然后创建一个新文件 resize.php
步骤 3:您还创建一个新的两个文件夹 1) image 和 2) image_thumb
步骤 4:然后创建一个新文件 image_upload.php
Yes i have a solution for uploaded image crop and resize without starch
please Following this steps:
step 1: you make a new index.php file.
step 2 : then make a new file resize.php
step 3 : you also make a new two folder 1) image and 2) image_thumb
step 4 : then after make a new file image_upload.php
这就是 imagecopyresampled 的作用:它重新缩放图像并且不裁剪它。尝试使用图像复制代替。
This is what imagecopyresampled does: it rescales the image and does not crop it. Try imagecopy instead.