CodeIgniter Forums
Image_lib watermark saves a blank image - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Image_lib watermark saves a blank image (/showthread.php?tid=53110)



Image_lib watermark saves a blank image - El Forum - 07-11-2012

[eluser]thisischris[/eluser]
Hello everyone. I'm trying to add a watermark to an image but it's just saving the original image.

Here is my code (it's in a helper).
Code:
function generate_text_thumbnail($text)
{
$CI =& get_instance();

$font = 'Sanchezregular.otf';

$config['image_library'] = 'gd2';
$config['source_image'] = './public/images/blank_thumb.png';
$config['new_image'] = './public/text_entries/test.png';
$config['dynamic_output'] = FALSE;
$config['create_thumb'] = FALSE;

$config['wm_text'] = $text;
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/' . $font;
$config['wm_font_size'] = '16';
$config['wm_font_color'] = '993300';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';


$CI->load->library('image_lib', $config);

return $CI->image_lib->watermark();
}

The function returns true, but the image (/public/text_entries/test.png) is exactly the same like the original. I'm struggling to see where I've gone wrong. Any input would greatly be appreciated.

I've made sure that it's not loading the library twice by removing $CI->load->library('image_lib', $config); which then gave me a PHP error saying 'Call to a member function watermark() on a non-object'

Thank you.


Image_lib watermark saves a blank image - El Forum - 07-11-2012

[eluser]thisischris[/eluser]
$this->image_lib->display_errors() is returning nothing either. Also $this->image_lib->watermark() is returning TRUE.

I have tried:
adding $config['angle_rotation'] = 180;
and then replaced $this->image_lib->watermark() with $this->image_lib->rotation()
And it was successful at rotating the image.

Cheers


Image_lib watermark saves a blank image - El Forum - 07-11-2012

[eluser]CroNiX[/eluser]
One thing you can try:
Code:
$CI->load->library('image_lib');
$CI->image_lib->initialize($config);
I know the image_lib has some problems when passing the config to it when loading the library, but works if you initialize it separately. Maybe this is one of those cases.


Image_lib watermark saves a blank image - El Forum - 07-11-2012

[eluser]thisischris[/eluser]
[quote author="CroNiX" date="1342035865"]One thing you can try:
Code:
$CI->load->library('image_lib');
$CI->image_lib->initialize($config);
I know the image_lib has some problems when passing the config to it when loading the library, but works if you initialize it separately. Maybe this is one of those cases.[/quote]

Thank you for your reply. The only change now is $this->image_lib->watermark() is now returning false. But display_errors() is still showing nothing.


Image_lib watermark saves a blank image - El Forum - 07-13-2012

[eluser]thisischris[/eluser]
bump


Image_lib watermark saves a blank image - El Forum - 07-13-2012

[eluser]Aken[/eluser]
You might need to just pick apart the library and see where it's choking up. There's a LOT going on in there, and your config looks fine at first glance (might want to double check all your file paths, make sure $text actually has a value, etc). Hard for us to say something specific, unless it's something really dumb and simple that everyone is missing.