views:

717

answers:

1

I'm hoping someone can help me. I'm trying to upload an image via a form, resize it to 600px, create a 100px thumbnail and then add a watermark image to the 600px version, but the code below is just creating two versions of the original image.

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

It doesn't look like you told it to make a copy for the thumbnail.

//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);

You might also want to put in error checking code so you know if it fails and why:

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