PHP Image使用给定的比例调整大小

时间:2015-01-27 09:46:55

标签: php image resize image-resizing

我在浏览器中有一个用于图像裁剪的JQuery插件。它的工作问题是我不理解这个“规模”部分。

原始图片尺寸:640x640

Jquery断头台插件结果数据:

{ scale: 0.9, angle: 0, x: 10, y: 20, w: 400, h: 400 }

我对比例感到困惑。

[编辑]:

这是我的PHP代码:

$filename = $this->data['img_file'];
$scale = round($this->data['scale'],2);
$angle = 360 - $this->data['angle'];
$x = $this->data['x'];
$y = $this->data['y'];
$w = $this->data['w'];
$h = $this->data['h'];

list($width, $height) = getimagesize($filename);
$new_width = $width * $scale;
$new_height = $height * $scale;

$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

$image_s = imagecreatetruecolor(400,400);
imagecopyresampled($image_s, $image_p, 0, 0, $x, $y, $w, $h, 400, 400);

[固定]

1 个答案:

答案 0 :(得分:1)

缩放将通常根据百分比调整图像大小。因此,如果将其保留为1,则应保持为100%,但裁剪图像实际上会从图像中删除像素,而更改比例则会缩小或放大图像像素间距。