Welcome Guest, Not a member yet? Register   Sign In
How in the world - Watermarking
#1

[eluser]Medikal[/eluser]
I've looked at the library, and I still can't figure out how in the world I can produce an image in my view, with text on it from a database value.

My main question is where I store the function to grab the value, where I write it to the picture, and how I display the manipulated picture in the view. No resizing, cropping, nothing, only watermarking a number on an image.

Thank you.
#2

[eluser]cereal[/eluser]
You can create a controller that would select the image from an image_list table through the id, something like this:

http://your.server/image/1

the controller will be:

Code:
<?php
class Image extends Controller {

    function Image()
    {
        parent::Controller();
    }
        
    function index($id)
    {
        $this->db->where('id',$id);
        $this->db->limit(1);
        $q = $this->db->get('image_list');

        $img = ($q->num_rows() != 0) ? $q->row() : FALSE;
    
        if($img == TRUE)
        {
            $this->load->library('image_lib');
            $config['source_image'] = './images/' . $img->file;
            $config['wm_text'] =  date('Y') .' © Copyright';
            $config['wm_type'] = 'text';
            $config['wm_font_size'] = '24';
            $config['wm_font_color'] = 'ffffff';
            $config['wm_vrt_alignment'] = 'bottom';
            $config['wm_hor_alignment'] = 'right';
            $config['wm_hor_offset'] = '-40';
            $config['wm_vrt_offset'] = '-20';
            $config['wm_padding'] = '0';
            $config['dynamic_output'] = TRUE;
            $this->image_lib->initialize($config);
            $this->image_lib->watermark();
        }
    }


}
?>

In order to display the image write:

Code:
<img src="http://your.server/image/1" />
#3

[eluser]Medikal[/eluser]
Right, didn't explain enough -- so for example I'm just using this for integers, it will have integers overlay the image (imagine the digg buttons). So I want the image url to be mysite.com/image/1 or mysite.com/image/4376.

So I setup my controller like so
Code:
function index($id)
    {

            $this->load->library('image_lib');
                        $config['source_image'] = 'myimage.png';
                        $config['wm_text'] = $id;
            $config['wm_type'] = 'text';
            $config['wm_font_path'] = 'text';
            $config['wm_font_size'] = '16';
            $config['wm_font_color'] = 'ffffff';
            $config['wm_vrt_alignment'] = 'bottom';
            $config['wm_hor_alignment'] = 'center';
            $config['wm_padding'] = '20';

            $this->image_lib->initialize($config);
            $this->image_lib->watermark();
      
    }


However, that completely errors out.
#4

[eluser]cereal[/eluser]
This is strange, it works fine for me. Add this:

Code:
if ( !$this->image_lib->watermark())
{
    echo $this->image_lib->display_errors();
}

Or if you are routing remove $id from index() and set $this->uri->segment(3) on wm_text.




Theme © iAndrew 2016 - Forum software by © MyBB