Php 为什么裁剪图像后会出现黑色区域?

Php 为什么裁剪图像后会出现黑色区域?,php,gd,crop,Php,Gd,Crop,我的代码裁剪图像: function cropimage($x1,$y1,$newwidth, $newheight) { $new_image = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($new_image, $this->image, $x1, $y1, 0, 0, $newwidth, $newheight, $this->getWidth

我的代码裁剪图像:

 function cropimage($x1,$y1,$newwidth, $newheight) {
            $new_image = imagecreatetruecolor($newwidth, $newheight);
            imagecopyresampled($new_image, $this->image, $x1, $y1, 0, 0, $newwidth, $newheight, $this->getWidth(), $this->getHeight());
            $this->image = $new_image;
            $this->image->save($file);
        }
结果:

为什么裁剪图像后会出现黑色区域?如何调整大小?

此代码修复了ok:

 imagecopyresampled($new_image, $this->image, 0, 0, $x1, $y1, $this->getWidth(), $this->getHeight(), $newwidth, $newheight);

正如手册中所说,第三个和第四个参数是针对目标x和y的,它们应该是0,第五个和第六个应该是$x1和$y1,我想……我试过了,但没有确定图像结果:位置裁剪是正确的,它只能删除黑色区域。最终图像大小是正确的裁剪大小吗?或者是原始尺寸?图像结果:黑色区域和图像交叉区域都是裁剪尺寸