笨图像处理(调整尺寸&水印)(CodeIgniter Image Manipulation (Res

2019-10-29 07:47发布

我希望有人能帮助我。 我想通过表单上传的图像,它调整到600px的,创建一个100px的缩略图,然后水印图像添​​加到600px的版本,但下面的代码只是创建原始图像的两个版本。

$image = $this->upload->data();
$resized = base_url()."images/artwork/".$image['orig_name'];

//Create 600px version
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 600;
$config['height'] = 600;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);

//Add watermark to 600px version
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './images/logo.gif';
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$this->image_lib->clear();
unset($config);

//Create 100px unwatermarked thumbnail
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);
$thumbnail = base_url()."images/artwork/".$image['raw_name']."".$image['file_ext'];

echo "<a href=\"".$resized."\"><img src=\"".$thumbnail."\" /></a>";

Answer 1:

它看起来并不像你告诉它做一个拷贝给缩略图。

//Create 100px unwatermarked thumbnail
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['create_thumb'] = TRUE;   // Tells it to make a copy called *_thumb.*
$config['width'] = 100;
$config['height'] = 100;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);

您可能还希望把错误校验码,所以你知道,如果它失败,原因如下:

if ( ! $this->image_lib->resize())
{
    echo $this->image_lib->display_errors();
}


Answer 2:

使用图像武也许会有帮助,按照本例: http://ellislab.com/forums/viewthread/162030/#778258



文章来源: CodeIgniter Image Manipulation (Resize & Watermark)