codeigniter中的库resize()无法正常工作?

时间:2013-09-05 04:50:23

标签: codeigniter image-resizing

我已经将图片上传到文件夹。现在我想要调整该图像的大小3次。首先调整图像大小为w:100,h:100,第二次调整图像大小为w:200,h:200 ,第三个将其调整为300:300

然后我在图像操作类的库中加载了像这样的函数库:: $ this-> load-> library('image_lib');

这是我的代码

$picturesData[$key][$key2] = $this->upload->data(); <<< this upload library is usable 

$file_name = $picturesData[$key][$key2]["file_name"];

//explode

$image_name = explode(".", $file_name);


//resize smallImage

$config['image_library'] = 'GD2';

$config['new_image'] = $path."/".$image_name[0]."_sSize";

// รูปที่เอามาใช้ในการ resize

$config['source_image'] = $picturesData[$key][$key2]["file_name"];

$config['create_thumb'] = TRUE;

$config['maintain_ratio'] = TRUE;

$config['width'] = 100;

$config['height'] = 100;

//mediumSize

$config['new_image'] = $path."/".$image_name[0]."_mSize";

$config['width'] = 200;

$config['height'] = 200;

//largeSize

$config['new_image'] = $path."/".$image_name[0]."_lSize";

$config['width'] = 300;

$config['height'] = 300;

$this->image_lib->initialize($config);

$this->image_lib->resize();


if(! $this->image_lib->resize()){

  echo $this->image_lib->display_errors();

}
这是我的错误!!     图像的路径不正确。

Your server does not support the GD function required to process this type of image.

The path to the image is not correct.

Your server does not support the GD function required to process this type of image.

The path to the image is not correct.

Your server does not support the GD function required to process this type of image.

Your server does not support the GD function required to process this type of image.

3 个答案:

答案 0 :(得分:1)

这似乎对我有用。 $ config ['source_image'] ='。/ image path / pic_name.jpg';

设置源路径..排除base_url()

答案 1 :(得分:0)

试试这个: -

$picturesData[$key][$key2] = $this->upload->data(); //this upload library is usable 
$file_name = $picturesData[$key][$key2]["file_name"];
//explode
$image_name = explode(".", $file_name);
//resize smallImage
$config['image_library'] = 'GD2';
$config['new_image'] = $path."/".$image_name[0]."_sSize.".$image_name[1];
//resize
$config['source_image'] = $picturesData[$key][$key2]["file_name"];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$this->image_lib->initialize($config);
$this->image_lib->resize();

//mediumSize
$config['new_image'] = $path."/".$image_name[0]."_sSize.".$image_name[1];
$config['width'] = 200;
$config['height'] = 200;
$this->image_lib->initialize($config);
$this->image_lib->resize();
//largeSize
$config['new_image'] = $path."/".$image_name[0]."_sSize.".$image_name[1];
$config['width'] = 300;
$config['height'] = 300;
$this->image_lib->initialize($config);
$this->image_lib->resize();

答案 2 :(得分:0)

连续Girish Sinha回答::更改此$ config ['source_image'] = $ picturesData [$ key] [$ key2] [“file_name”]; to $ config ['source_image'] = $ picturesData [$ key] [$ key2] [“full_path”];