裁剪后为什么我的图像会拉伸? [英] Why does my Image stretch when I crop it?

查看:129
本文介绍了裁剪后为什么我的图像会拉伸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码片段来裁剪图像?

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;
   }

在这里,$this->image是原始图像$this->getWidth()$this->getHeight()保留图片的原始尺寸,其中$width$height是裁剪区域.

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).

该如何解决?

推荐答案

好吧,问题出在源代码的尺寸上.给出整个图像的尺寸将重新调整大小,而不是裁剪.

Well, the problem is giving the source dimensions. Giving the dimensions of entire image will re size instead of cropping.

这应该可以解决问题

   function crop($width,$height) {
       $new_image = imagecreatetruecolor($width, $height);
       imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $width, $height );
       $this->image = $new_image;
   }

这篇关于裁剪后为什么我的图像会拉伸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆