1
Codeigniter에서 이미지 조작 라이브러리를 사용하고 비율을 유지하면서 최대 278px의 너비로 이미지의 크기를 조정해야합니다. 또한 이미지가 400px를 넘지 않도록해야합니다.먼저 크기를 조정할 때 이미지를자를 수 없습니다.
$this->image_lib->resize()
을 사용하여이 작업을 시도한 다음 $this->image_lib->crop()
을 사용하여 다시 실행하려고 시도했지만 크기를 조정하는 데 문제가 있습니다. 내가 직접 컨트롤러에서() crop_image를 호출 할 경우 예상대로, 그것은 작물
public function create_thumb($path) {
$data = $this->upload->data();
if ($data['image_width'] >= 278):
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 278;
$config['height'] = 400;
$config['quality'] = '90%';
$config['master_dim'] = 'width';
$this->load->library('image_lib', $config);
if ($this->image_lib->resize()):
$this->image_lib->clear();
endif;
endif;
$this->crop_image($path);
return false;
}
// Make max image size 278x400
public function crop_image($path) {
list($width, $height) = getimagesize($path);
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['x_axis'] = '0';
$config['y_axis'] = '0';
$config['maintain_ratio'] = FALSE;
$config['width'] = $width;
$config['height'] = 400;
$config['quality'] = '100%';
$this->load->library('image_lib', $config);
if ($this->image_lib->crop())
{
return true;
}
return false;
}
: 여기
두 모델입니다. 그러나 create_thumb()에서 호출 할 때 오류가 발생합니다.Your server does not support the GD function required to process this type of image.
이전에 이미지를자를 수 있고 GD가 phpinfo()에 따라 설치 되었기 때문에이 오류가 나타나는 이유에 대해 혼란스러워합니다.
문제는 image_lib를 두 번로드하는 것과 관련이 있다고 생각하지만 $this->image_lib->clear();
이 문제를 해결할 것이라고 생각하십니까?
내가 뭘 잘못하고 있니? 최대 278px 너비와 최대 400px 높이로 이미지의 크기를 조정할 수있는 더 좋은 방법이 있습니까?
역전 해 보셨습니까? 잘라내서 크기를 조정하거나 각 기능을 개별적으로 실행 하시겠습니까? – Jeemusu
@Jeemusu Ya, 둘 다 별도로 작동합니다. 일단 내가 그들을 함께하면, 그들은 실패하고 질문에 게시 된 오류가 발생합니다. – Motive