CodeIgniter Forums
image_lib watermarking - view part - 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 watermarking - view part (/showthread.php?tid=37196)

Pages: 1 2


image_lib watermarking - view part - El Forum - 01-01-2011

[eluser]Casperlarsen94[/eluser]
I'm trying to learn the codeigniter image libary, and i can't find anything about the view part in watermarking an image.

Controller
Code:
$config['source_image']    = 'http://websplus.dk/images/layout/banner.png';
$config['wm_text'] = 'Taranto Ultras';
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size']    = '22';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'left';
$config['wm_padding'] = '20';

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

$this->image_lib->watermark();

How should my view look like? Confused

I hope you guys can help me Smile

And happy new year Big Grin


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Cristian Gilè[/eluser]
Hi Casperlarsen94,

in the view something like this:

Code:
<img src='path/to/your/watermarked/image' alt='my watermarked image' />

Cristian Gilè


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Casperlarsen94[/eluser]
Is it possible to add my watermark to ONE image depending on the URL?

For example, if the url www.example.com/banner/casperlarsen then the watermark text should be casperlarsen.
Or if the url is www.example.com/banner/johndoe the text should be johndoe


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Nick_MyShuitings[/eluser]
Since you are adding the watermark text in the controller... and since the controller has access to the name.... connect the dots and it should be possible


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Cristian Gilè[/eluser]
Code:
$config['source_image']    = 'http://websplus.dk/images/layout/banner.png';
$config['wm_text'] = $this->uri->segment(3, 'default text'); //http://ellislab.com/codeigniter/user-guide/libraries/uri.html
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size']    = '22';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'left';
$config['wm_padding'] = '20';

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

$this->image_lib->watermark();

Cristian Gilè


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Casperlarsen94[/eluser]
I know how to get the name from URL in to a string.
But i don't know how to pass there config and the watermark information to my view, and then create the image?


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Cristian Gilè[/eluser]
The path of the image (source_image) must be a relative or absolute server path, not a URL.

Cristian Gilè


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Casperlarsen94[/eluser]
But how schould the view look like?
I don't understand it, sorry.


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Cristian Gilè[/eluser]
You have an image on your server and you have set its path in $config['source_image']. When you do

Code:
$this->image_lib->watermark();

the image has been watermarked.

In your view, now, you can show the image with the img tag:
Code:
<img src='path/to/your/image' alt='my watermark image' />

If you need to restrict access to your images, read this

Cristian Gilè


image_lib watermarking - view part - El Forum - 01-09-2011

[eluser]Casperlarsen94[/eluser]
This doesn't works?

My Controller
Code:
class Test extends Controller
{
    function index()
    {
        $config['source_image']    = '/banner/images/banner.png';
        $config['wm_text'] = 'Casper Larsen';
        $config['wm_type'] = 'text';
        $config['wm_font_path'] = './system/fonts/texb.ttf';
        $config['wm_font_size']    = '22';
        $config['wm_font_color'] = 'ffffff';
        $config['wm_vrt_alignment'] = 'top';
        $config['wm_hor_alignment'] = 'left';
        $config['wm_padding'] = '20';

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

        $this->image_lib->watermark();
        
        $this->load->view('test_view');
    }
}

My View
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<img src="http://localhost:8888/banner/images/banner.png" alt="Banner" />

&lt;/body&gt;
&lt;/html&gt;