bug (?) codeigniter 作物图像高度和宽度改变
bug (?) codeigniter crop image height and width changed
我从 UI 发送了 source_image
、x_axis
、y_axis
、height
和 width
来处理图像(在这种情况下我裁剪了一张图片),这是我的代码:
$this->load->library('image_lib');
$image = $this->input->post('source_image');
//array configuration for clock-wise and counter-clock-wise
$angle = array(
0 => 0,
90 => 270,
180 => 180,
270 => 90
);
$rotation = $this->input->post('rotation');
$x = $this->input->post('x');
$y = $this->input->post('y');
$width = $this->input->post('width');
$height = $this->input->post('height');
$result = array();
$config['image_library'] = 'gd2';
$config['source_image'] = $image;
$config['x_axis'] = $x;
$config['y_axis'] = $y;
$config['maintain_ratio'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->initialize($config);
if (!$this->image_lib->crop()) {
$result = array(
'result' => FALSE,
'error' => $this->image_lib->display_errors()
);
}
当我完成裁剪图像然后再次检查它更改的分辨率时,例如:
width: 197px;
height: 173px;
裁剪完应该是那个分辨率,但是我检查的时候分辨率变成了
width: 181px;
height: 173px;
在其他情况下,有时宽度会变化,有时高度也会变化..
我在配置 $config
时错了吗?谢谢
那么你不应该使用 $config['maintain_ratio'] = TRUE;
(将其设置为 false)。
Since the maintain_ratio option is enabled, the image will be as close
to the target width and height as possible while preserving the
original aspect ratio.
文档:https://www.codeigniter.com/userguide3/libraries/image_lib.html#processing-an-image
请记住,更改比例或将其设置为 false 以使尺寸成为硬值会导致某些图像倾斜或看起来很奇怪。 CI 没有办法真正处理这个问题,但还有其他上传库可以在保持指定大小的同时添加黑条,例如:https://github.com/verot/class.upload.php
我从 UI 发送了 source_image
、x_axis
、y_axis
、height
和 width
来处理图像(在这种情况下我裁剪了一张图片),这是我的代码:
$this->load->library('image_lib');
$image = $this->input->post('source_image');
//array configuration for clock-wise and counter-clock-wise
$angle = array(
0 => 0,
90 => 270,
180 => 180,
270 => 90
);
$rotation = $this->input->post('rotation');
$x = $this->input->post('x');
$y = $this->input->post('y');
$width = $this->input->post('width');
$height = $this->input->post('height');
$result = array();
$config['image_library'] = 'gd2';
$config['source_image'] = $image;
$config['x_axis'] = $x;
$config['y_axis'] = $y;
$config['maintain_ratio'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->initialize($config);
if (!$this->image_lib->crop()) {
$result = array(
'result' => FALSE,
'error' => $this->image_lib->display_errors()
);
}
当我完成裁剪图像然后再次检查它更改的分辨率时,例如:
width: 197px;
height: 173px;
裁剪完应该是那个分辨率,但是我检查的时候分辨率变成了
width: 181px;
height: 173px;
在其他情况下,有时宽度会变化,有时高度也会变化..
我在配置 $config
时错了吗?谢谢
那么你不应该使用 $config['maintain_ratio'] = TRUE;
(将其设置为 false)。
Since the maintain_ratio option is enabled, the image will be as close to the target width and height as possible while preserving the original aspect ratio.
文档:https://www.codeigniter.com/userguide3/libraries/image_lib.html#processing-an-image
请记住,更改比例或将其设置为 false 以使尺寸成为硬值会导致某些图像倾斜或看起来很奇怪。 CI 没有办法真正处理这个问题,但还有其他上传库可以在保持指定大小的同时添加黑条,例如:https://github.com/verot/class.upload.php