Page 2 of 2

Re: I Added (Custom) Text Watermark Code **

Posted: Wed Sep 21, 2011 9:18 am
by perezosogato
arkarwmh wrote: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
does it work on v1.5.1.x? thanks

[Edit] I tested, it works on v1.5.1.2.
but the words is right on the left corner. How to put the watermark in the center ?

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

Posted: Mon Oct 17, 2011 10:08 pm
by rgtobr
And how to resize watermark in each image size? I tried to put watermark and it works, but the watermark has only one size for all images (in my case 500x500px).



Observation: in file ../system/library/image.php, I think the function create($image) is not working fine because I needed to replace the line

Code: Select all

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

Code: Select all

imagecopymerge($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height, 10);
to function recognize my watermark in PNG format.

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

Posted: Sun Mar 10, 2013 1:31 am
by paulosam
I made new Watermark Module called "Samcholi Watermark".

It is very easy to use.

I recommend you to use it.

Regards.

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

Posted: Thu Apr 04, 2013 11:43 pm
by OSWorX
And I recommend this here: http://osworx.net/en/development/43-ope ... watermarks
Simply the easiest watermark module for OpenCart.

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

Posted: Tue Jun 23, 2015 10:47 pm
by storm-cloud
Great news! I didn't even realise this function was built into the core.

A quick question. In catalog/model/tool/image.php there is an if statement that needs to be set to true in order to force watermarking (if the image is of the correct dimensions).

Code: Select all

if ($width_orig != $width || $height_orig != $height) {
Would it be possible to also include images from a specific directory? I want to ensure all product images are watermarked but not other images.

For example, something like:

Code: Select all

if ($width_orig != $width || $height_orig != $height || $some_variable == 'product_images') {
Edit: I found a solution.

Code: Select all

if ($width_orig != $width || $height_orig != $height || strpos($path,'/product_images/') !== false) {
Would this be the best method or is there a better way to handle this test?

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

Posted: Wed Oct 21, 2015 1:57 pm
by jasonc310771
W.Creater wrote:I have one question about the watermarked images. Is watermarked images are cached by the Google or not?
A little late I know, but to answer this question for 'all' Opencart version, Yes Google will index all images that we see in the shopping cart.

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

Posted: Wed Oct 21, 2015 3:25 pm
by BettyeDth
jasonc310771 wrote:
W.Creater wrote:I have one question about the watermarked images. Is watermarked images are cached by the Google or not?
sony xperia z5 handyhülle
A little late I know, but to answer this question for 'all' Opencart version, Yes Google will index all images that we see in the shopping cart.
yes, the watermarked images are cached by the Google.

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

Posted: Thu Apr 06, 2017 6:40 pm
by danncti
Opencart 2.1.0.2

Code: Select all

	$image = new Image(DIR_IMAGE . $old_image);
	$image->resize($width, $height);
	
	// you have to add this two lines 
        $imageW = new Image(DIR_IMAGE . 'path/to/image/in/image/folder.png'); 
        $image->watermark($imageW, 'bottomright'); //   topleft , topright , bottomleft  or bottomright
	
	$image->save(DIR_IMAGE . $new_image);

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

Posted: Sat Nov 18, 2017 2:47 am
by pla1829
danncti wrote:
Thu Apr 06, 2017 6:40 pm
Opencart 2.1.0.2

Code: Select all

	$image = new Image(DIR_IMAGE . $old_image);
	$image->resize($width, $height);
	
	// you have to add this two lines 
        $imageW = new Image(DIR_IMAGE . 'path/to/image/in/image/folder.png'); 
        $image->watermark($imageW, 'bottomright'); //   topleft , topright , bottomleft  or bottomright
	
	$image->save(DIR_IMAGE . $new_image);
Not working on v2.3.0.2 if anyone tries...