Page 3 of 3

Re: watermark

Posted: Mon Jul 04, 2011 12:55 am
by yop289
Thank you very much. Perfect explain. It works with Version 1.5.0 aswell.

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

Posted: Tue Jul 26, 2011 4:54 am
by SXGuy
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

Is there any way to apply this only to images bigger than 200px?

Re: watermark

Posted: Wed Sep 07, 2011 8:34 pm
by Kulsha
siuksliadeze wrote:You can also define minimum width or height of your image to which the watermark will be added (if you want watermarks appear even on thumbnails, put 0)
The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.

I am wondering if I can tell the script NOT to use watermark on my main home page banners - which are 952px x 280px. I am using a theme that uses a nivo slider that takes the banner images from the images directory. And the watermark script although perfect for the images in the catalogue pages are also applying watermark to my main home page banners as they are larger than the thumbnails.

Any hints on how to code this would be fantastic. Thanks.

Re: watermark

Posted: Fri Sep 16, 2011 9:15 pm
by terrier
you can use do the following:

Code: Select all

if ($width < 900 || $height < 250) {   
   $image->watermark(DIR_IMAGE . 'watermark.png', 'center'); 
}
Kulsha wrote:
siuksliadeze wrote:You can also define minimum width or height of your image to which the watermark will be added (if you want watermarks appear even on thumbnails, put 0)
The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.

I am wondering if I can tell the script NOT to use watermark on my main home page banners - which are 952px x 280px. I am using a theme that uses a nivo slider that takes the banner images from the images directory. And the watermark script although perfect for the images in the catalogue pages are also applying watermark to my main home page banners as they are larger than the thumbnails.

Any hints on how to code this would be fantastic. Thanks.

Re: watermark

Posted: Thu Sep 22, 2011 4:44 pm
by perezosogato
siuksliadeze wrote:I was looking for instructions to create a good watermark on the images, but I nearly got lost between the threads in this forum on how to make it work.
Therefore I decided to put all the suggestions that I found useful for me.

The code below includes watermark method fix (thanks to acidline!) useful code enhancements that allow to center watermark in the image (thanks to dedurus!) and also define the minimum image size for which the watermark will be applied (that was added by myself).
These watermarks are applied upon image resize, so the watermarks are not added as an overlay but as a part of original image (option suggested by JAY6390 in http://forum.opencart.com/viewtopic.php?t=16533). This solves the issue that original image can still be fetched without the watermark.

These instructions are valid for Opencart 1.4.9.1 and 1.4.9.2 (I did this on v. 1.4.9.2)
1. Create PNG watermark, name it as watermark.png and copy it to image/ folder of your Opencart installation (yes, it works fine with PNG files).
2. Now edit 2 PHP files
3. The first file: system/library/image.php
Go to lines 93-121 and you will see the following code:

Code: Select all

public function watermark($file, $position = 'bottomright') {
        $watermark = $this->create($file);
        
        $watermark_width = imagesx($watermark);
        $watermark_height = imagesy($watermark);
        
        switch($position) {
            case 'topleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = 0;
                break;
            case 'topright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = 0;
                break;
            case 'bottomleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
            case 'bottomright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
        }
        
        imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40);
        
        imagedestroy($watermark);
    }
You have to replace this code with the code below (the code includes a watermark method fix described by acidline and option to center watermark in the image described by dedurus in this thread above):

Code: Select all

public function watermark($file, $position = 'bottomright') {
   
   //Pb ! you don't work on the true object => you must modify the "create" method ($mime = $this->info['mime']; it's work only if we have the same image format !
        //$watermark = $this->create($file);

        //Prefer PNG files => it's not optimized but it's work
   $watermark = imagecreatefrompng($file);
        
        $watermark_width  = imagesx($watermark);
        $watermark_height = imagesy($watermark);

        switch($position) {
            case 'topleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = 0;
                break;
            case 'topright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = 0;
                break;
            case 'bottomleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
            case 'bottomright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
			case 'center': 
				$watermark_pos_x = ($this->info['width']- $watermark_width)/2;
				$watermark_pos_y = ($this->info['height']- $watermark_height)/2;
				break;
        }
       
        imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height);
        
        imagedestroy($watermark);
    }
4. Second file to edit is catalog/model/tool/image.php
Go to line 27 and you will see the follwing line:

Code: Select all

$image = new Image(DIR_IMAGE . $old_image);
Right after this line add the following code:

Code: Select all

if ($width > 400 || $height > 300) {	
	$image->watermark(DIR_IMAGE . 'watermark.png', 'center'); 
}
In the code above you can define desired position of the watermark (topleft, topright, bottomleft, bottomright or center).
You can also define minimum width or height of your image to which the watermark will be added (if you want watermarks appear even on thumbnails, put 0)

5. Final step: delete all data in folder image/cache/data in order to have the images recreated with watermarks.
That's it!
I hope I helped to those who have problems making watermarks work.

Not working v1.50....

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

Posted: Thu Sep 22, 2011 4:45 pm
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
is it possible to put the watermark in the center ??? thank you

Re: watermark

Posted: Thu Sep 22, 2011 4:51 pm
by uksitebuilder
One thing I will say is if you are submitting your product to Google Shopping, they will probably reject the images if they are watermarked.

Re: watermark

Posted: Thu Sep 22, 2011 5:04 pm
by perezosogato
uksitebuilder wrote:One thing I will say is if you are submitting your product to Google Shopping, they will probably reject the images if they are watermarked.

why ??? Google support people to add watermark to the image though

Re: watermark

Posted: Thu Sep 22, 2011 5:11 pm
by uksitebuilder

Re: watermark

Posted: Thu Sep 22, 2011 5:27 pm
by perezosogato
uksitebuilder wrote:I dont make the rules

http://www.google.com/support/forum/p/b ... 6c0e&hl=en

it just marked not allow promotional logo / words.

Re: watermark

Posted: Thu Sep 22, 2011 5:42 pm
by uksitebuilder
http://www.google.com/support/merchants ... wer=188484

Your images may not contain promotional messages of any kind, including watermarks or promotional text

Re: watermark

Posted: Thu Sep 22, 2011 6:02 pm
by perezosogato
Language and Promotional Messages

Use standard spelling and grammar. Avoid any repeated, unnecessary or excessive use of punctuation, capitalization or symbols. Don't use exclamation points in your product titles unless the official product title contains them. The use of symbols, numbers, and letters have to adhere to the true meaning of the symbol.
The only exception to excessive capitalization is if your company name is written in all capital letters. In such a case it is permissible to submit your company name in all capital letters, i.e. “ACME Inc.”
Avoid offensive or inappropriate language.
Promotional or boilerplate text may not be included in your store name and product data. All data needs to be a clear and direct description of the submitted product. Text related to shopping or store policies is not allowed. For example, "Free shipping" is not allowed.
Your images may not contain promotional messages of any kind, including watermarks or promotional text. You are not allowed to submit image links to logo images or other generic images.
free shipping is not allowed...

Re: watermark

Posted: Mon Oct 03, 2011 6:52 pm
by yaseenghanchi
@ Daniel



Where i post this code ???

Re: watermark

Posted: Thu Oct 06, 2011 8:39 am
by victor.gatto
can someone please confirm if it works on 1.5.1.1, thanks alot.

Re: watermark

Posted: Thu May 24, 2012 4:35 am
by Bukoptimistas
siuksliadeze solution (http://forum.opencart.com/viewtopic.php ... 20#p114659) works on Version 1.5.2.1

Re: watermark

Posted: Sun Feb 03, 2013 11:06 pm
by Lao
terrier wrote:you can use do the following:

Code: Select all

if ($width < 900 || $height < 250) {   
   $image->watermark(DIR_IMAGE . 'watermark.png', 'center'); 
}
Kulsha wrote:
siuksliadeze wrote:You can also define minimum width or height of your image to which the watermark will be added (if you want watermarks appear even on thumbnails, put 0)
The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.

I am wondering if I can tell the script NOT to use watermark on my main home page banners - which are 952px x 280px. I am using a theme that uses a nivo slider that takes the banner images from the images directory. And the watermark script although perfect for the images in the catalogue pages are also applying watermark to my main home page banners as they are larger than the thumbnails.

Any hints on how to code this would be fantastic. Thanks.
Hello all!

I was having the same issue with banners. I followed terrier's advice, but tweaked it a little:

Code: Select all

if ($width < 900 || $height > 400) {
I am using 640x480 for product images and 980x270 for banners.

The remaining problem and a pretty strange one is that it puts the watermark on the thumbnails (although I didn't delete the cache, so it might be this creating the problem) and only on additional images. The main product image doesn't have the watermark when you make it bigger.

I guess it has something to do with JNeuhoff's Import/Export tool, but I'm not sure where to look for the issue.

Example (see the main and second image):
http://www.importpieseauto.ro/uleiuri/c ... td-5w40-5l

Re: watermark

Posted: Tue Feb 05, 2013 3:51 am
by Lao
Anyone??!