Page 1 of 2

[How to] Add watermark to image???

Posted: Mon Jun 28, 2010 1:42 pm
by amdev
I found this function in system/library/image.php.
How to use it???


Regards.
Amdev

Re: [How to] Add watermark to image???

Posted: Wed Jul 07, 2010 8:05 am
by Melanie
Any news on this?

I am interested in this as well.

thanks,
Melanie

Re: [How to] Add watermark to image???

Posted: Wed Jul 07, 2010 10:11 am
by JAY6390
Well if you want it to be on every resized image, you'll need to just add it to the file

Code: Select all

/catalog/model/tool/image.php file
find this line

Code: Select all

$image = new Image(DIR_IMAGE . $old_image); 
and put it after that if you want the watermark put on before the image gets resized, or after

Code: Select all

$image->resize($width, $height); 
something like

Code: Select all

$image->watermark(DIR_IMAGE . 'path/to/image/in/image/folder.png', 'position-name-here'); 
replacing the position-name-here with either
- topleft
- topright
- bottomleft
- bottomright

Note this has not been tested, but should work

Re: [How to] Add watermark to image???

Posted: Wed Jul 07, 2010 11:18 am
by Melanie
Hi,

I tried the above but it didn't work. :-[

Im running v.1.48b

Any instructions for enabling the watermark feature?

Thanks,
Melanie

Re: [How to] Add watermark to image???

Posted: Wed Jul 07, 2010 12:59 pm
by amdev
Melanie wrote:Hi,

I tried the above but it didn't work. :-[

Im running v.1.48b

Any instructions for enabling the watermark feature?

Thanks,
Melanie
Me too, it didn't work.
this my code

Code: Select all

                        $image = new Image(DIR_IMAGE . $old_image);
			$image->resize($width, $height);
			$image->watermark(DIR_IMAGE . 'data/watermark.png', 'topleft'); 
			$image->save(DIR_IMAGE . $new_image);
                        
Have any instruction???

Thanks.

Re: [How to] Add watermark to image???

Posted: Wed Jul 07, 2010 6:47 pm
by JAY6390
Seems there was an error in the watermark code
Edit the file

Code: Select all

/system/library/image.php
find this line

Code: Select all

imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40); 
replace with this line

Code: Select all

imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height); 
Note you will need to delete all of your images located in

Code: Select all

/image/cache/data/
to get the images recreated for your cache

Re: [How to] Add watermark to image???

Posted: Thu Jul 08, 2010 1:49 pm
by amdev
JAY6390 wrote:Seems there was an error in the watermark code
Edit the file

Code: Select all

/system/library/image.php
find this line

Code: Select all

imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40); 
replace with this line

Code: Select all

imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height); 
Note you will need to delete all of your images located in

Code: Select all

/image/cache/data/
to get the images recreated for your cache
Thanks JAY6390 so much for ur advice.
I tried but it didn't work. ??? ???

Regard.

Re: [How to] Add watermark to image???

Posted: Thu Jul 08, 2010 6:24 pm
by JAY6390
Have you create a file called watermark.png with an image in the /image/data/ folder? My watermark was actually a jpg file (my avatar off here to be precise)

Re: [How to] Add watermark to image???

Posted: Fri Jul 09, 2010 11:44 am
by amdev
JAY6390 wrote:Have you create a file called watermark.png with an image in the /image/data/ folder? My watermark was actually a jpg file (my avatar off here to be precise)
Yes, i did it.

Re: [How to] Add watermark to image???

Posted: Fri Jul 09, 2010 6:11 pm
by JAY6390
Excellent, what was the issue with it?

Re: [How to] Add watermark to image???

Posted: Sat Jul 10, 2010 12:01 pm
by lillolollo
For png wtm you must use imagecopymerge not imagecopy

Code: Select all

   imagecopymerge($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height,75);  

Re: [How to] Add watermark to image???

Posted: Sun Jul 11, 2010 7:29 pm
by amdev
lillolollo wrote:For png wtm you must use imagecopymerge not imagecopy

Code: Select all

   imagecopymerge($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height,75);  
Thanks,
Work done!!!

Re: [How to] Add watermark to image???

Posted: Mon Jul 12, 2010 11:21 am
by dramony
any screen shots?

Re: [How to] Add watermark to image???

Posted: Mon Jul 12, 2010 6:28 pm
by amdev
dramony wrote:any screen shots?
Image of watermark must be .jpg.
Because image in cache/data/ are all of .jpg
so, don't use imagecopymerge() function.

Re: [How to] Add watermark to image???

Posted: Fri Jul 30, 2010 11:08 pm
by jty
amdev wrote: Image of watermark must be .jpg.
Because image in cache/data/ are all of .jpg
so, don't use imagecopymerge() function.
Hello, I am a litle bit confused. I am reading that the watermark image has to have the same extension as the images. But I am also reading to use a png to get a transaparent watermark

My images are .jpg but I would like to have a "transparent" watermark, either .gif or png.
Is this possible ? I have the watermark working as a .jpg but I need it to be transparent on my .jpg files.

Does this mean that I have to convert my image files to .png or .gif to be able to use the transparency of gifs and pngs ?
Thanks in advance

Re: [How to] Add watermark to image???

Posted: Wed Aug 11, 2010 7:31 am
by Melanie
I have exactly the same problem.

My images are all JPG

I want to use a PNG watermark but it wont work.

JPG watermark works fine.

Any advice.......
Thanks,
Melanie.

Re: [How to] Add watermark to image???

Posted: Sat Oct 16, 2010 4:54 am
by IOWA
Why don't you guys just use photoshop or gimp (free open source) to water mark your images?

Re: [How to] Add watermark to image???

Posted: Fri Nov 26, 2010 12:15 am
by siuksliadeze
I just added my watermark "howto" in my post here: http://forum.opencart.com/viewtopic.php ... 59#p114659

I Added (Custom) Text Watermark Code **

Posted: Sun Mar 20, 2011 7:08 am
by arkarwmh
I found a Watermark code online.
So i combined into my Opencart.

NO NEED OPENCART BUILTIN WATERMARK() FUNCTION.
NO NEED ANY IMAGE FILE FOR WATERMARK.
JUST USE TEXT WATERMARKS.

1. Find this code in the file 'system/library/image.php'
(Its in the save() function)

Code: Select all

if ($extension == 'jpeg' || $extension == 'jpg') {
2. Add following piece of codes AFTER.

Code: Select all

$width = imagesx($this->image);
$height = imagesy($this->image);
$statement = 'Copyright to www.yourwebsite.com';
$fontsize = 2;
foreach (range($fontsize, 1) as $_fontsize) {
	$fontw = imagefontwidth($_fontsize);
	$fullw = strlen($statement) * $fontw;
	if ($fullw + 4 <= $width) {
		break;
	}
}
$fonth = imagefontheight($_fontsize);
$black = imagecolorallocate($this->image, 0, 0, 0);
$gray = imagecolorallocate($this->image, 200, 200, 200);
$white = imagecolorallocate($this->image, 255, 255, 255);

// imagefilledrectangle($this->image, // The graphics object to draw on
	// $width - $fullw - 4,  // The X value of upper left corner
	// $height - $fonth - 4, // The Y value of upper left corner
	// $width,               // The X value of lower right corner
	// $height,              // The Y value of lower right corner
	// $gray);              // The color

imagestring($this->image, // The graphics object to draw on
	$fontsize,            // The font size to use.
	$width - $fullw - 2,  // X value of upper left corner
	$height - $fonth - 2, // Y value of upper left corner
	$statement,           // The text to print
	$gray);              // The color to do it with.

Enjoy!
Regards,
Arkar :clown:
arkarwmh@gmail.com

Re: [How to] Add watermark to image???

Posted: Wed Aug 10, 2011 9:13 pm
by W.Creater
I have one question about the watermarked images. Is watermarked images are cached by the Google or not?