2010-02-09 105 views
0

我希望有人能帮助我。我试图通过表单上传图片,将其大小调整为600px,创建一个100px的缩略图,然后将水印图像添​​加到600px版本,但下面的代码仅创建原始图像的两个版本。CodeIgniter图像处理(调整大小和水印)

$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>"; 

回答

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(); 
}