PHP-使用imagecopyresampled()裁剪图像? [英] PHP - cropping image with imagecopyresampled()?

查看:70
本文介绍了PHP-使用imagecopyresampled()裁剪图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用imagecreatetruecolor裁切图像,并且总是裁切它留下黑色空间,或者缩放太大。我希望图像恰好为191px宽和90px高,因此我还需要调整图像大小以及裁剪,因为必须保持该比例。好吧,有一些项目示例:

I'd like to crop an image using imagecreatetruecolor and it always crops it leaving black spaces, or the zoom is too big. I want the image to be exactly 191px wide and 90px high, so I also need to resize the image, as well as crop, because the ratio has to be kept. Well, there are some samples of the project:

调整大小脚本(简化后)如下所示:

The resize script (simplified) goes like this:

$src_img=imagecreatefromjpeg($photoTemp);    
list($width,$height)=getimagesize($photoTemp);
$dst_img=imagecreatetruecolor(191, 90);
imagecopyresampled($dst_img, $src_img, 0, 0, $newImage['crop']['x'], $newImage['crop']['y'], $newImage['crop']['width'], $newImage['crop']['height'], $width, $height);

$ newImage ['crop']数组包括:

The $newImage['crop'] array includes:

['x'] => $_POST['inp-x']
['y'] => $_POST['inp-x']
['width'] => $_POST['inp-width']
['height'] => $_POST['inp-height']

但是我得到的是:

有人看到了,我在做什么错了吗?

Anyone sees, what I'm doing wrong?

谢谢麦克。

推荐答案

好,我自己发现了问题,代码应如下所示:

Ok, I found the problem myself, the code should be like this:

imagecopyresampled($dst_img, $src_img, 0, 0, $newImage['crop']['x'], $newImage['crop']['y'], $newImage['newWidth'], 191, 90, $newImage['crop']['height']); 

这篇关于PHP-使用imagecopyresampled()裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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