我想创建缩略图,同时调整图像,所以在这里多待明确的是,我试图裁剪图像:创建缩略图和调整问题
而且我想切出那个红色区域。
现在我的问题是,我调整我的HTML图像croping所以之前,当我将数据提交到PHP时得到不正确的值,如y = 100
时候真的也可能是y = 200
所以我需要找到一种方法来计算自己的价值观。
我正在使用imagecopyresampled
,也许有更好的命令呢?
而且我最亲密的soliution是这样的:
imagecopyresampled(
$thumb, //Destination image link resource.
$src, //Source image link resource.
0, //x-coordinate of destination point.
0, //y-coordinate of destination point.
0, //x-coordinate of source point.
0, //y-coordinate of source point.
120, //Destination width.
160, //Destination height.
$image_width/2, //Source width.
$image_height/2 //Source height.
);
在这种情况下,将切出左侧角球,但尺寸会不一样,我的红盒子。 所以我想我需要得到source width
和source height
权和其他一切应该伏贴,反正我希望我在这里做任何意义:)
编辑对不起,我忘了提,$image_width
和$image_height
是原始图像大小
EDIT 2更清楚,这是我所得到的,当我使用此代码
$dimensions = getimagesize('testas.jpg');
$img = imagecreatetruecolor(120, 160);
$src = imagecreatefromjpeg('testas.jpg');
imagecopyresampled($img, $src, 0, 0, 0, 0, 120, 160, $dimensions[0]/2, $dimensions[1]/2);
imagejpeg($img, 'test.jpg');
调整
调整后的图像大小是正确的,但正如你所看到的,它看起来不正确。
您使用哪些命令获取不正确的值?如果按照BenM的建议在上传后使用'getimagesize',那应该没问题。 – 2012-02-18 23:19:24