我希望有人可以帮助我。我正在尝试通过表单上传图像,将其调整为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>";
答案 0 :(得分:3)
看起来你没有告诉它为缩略图制作副本。
//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();
}
答案 1 :(得分:0)
根据此示例,使用Image Moo可能有所帮助:http://ellislab.com/forums/viewthread/162030/#778258