Post by yop289 » Mon Jul 04, 2011 12:55 am

Thank you very much. Perfect explain. It works with Version 1.5.0 aswell.

Expert in OpenCart, visit my other modules.
http://www.opencart.com/index.php?route ... ame=yop289
Custom coder, what you need you will have


Active Member

Posts

Joined
Sat Jun 25, 2011 1:49 am

Post by SXGuy » Tue Jul 26, 2011 4:54 am

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?

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by Kulsha » Wed Sep 07, 2011 8:34 pm

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.

Newbie

Posts

Joined
Wed Jul 16, 2008 3:44 pm

Post by terrier » Fri Sep 16, 2011 9:15 pm

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.

New member

Posts

Joined
Wed Aug 31, 2011 7:05 pm

Post by perezosogato » Thu Sep 22, 2011 4:44 pm

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....

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by perezosogato » Thu Sep 22, 2011 4:45 pm

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

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by uksitebuilder » Thu Sep 22, 2011 4:51 pm

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.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by perezosogato » Thu Sep 22, 2011 5:04 pm

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

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by uksitebuilder » Thu Sep 22, 2011 5:11 pm


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by perezosogato » Thu Sep 22, 2011 5:27 pm

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.

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by uksitebuilder » Thu Sep 22, 2011 5:42 pm

http://www.google.com/support/merchants ... wer=188484

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

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by perezosogato » Thu Sep 22, 2011 6:02 pm

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...

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by yaseenghanchi » Mon Oct 03, 2011 6:52 pm

@ Daniel



Where i post this code ???

Newbie

Posts

Joined
Mon Oct 03, 2011 6:44 pm
Location - Karachi, Pakistan

Post by victor.gatto » Thu Oct 06, 2011 8:39 am

can someone please confirm if it works on 1.5.1.1, thanks alot.

Active Member

Posts

Joined
Thu Sep 01, 2011 9:14 am

Post by Bukoptimistas » Thu May 24, 2012 4:35 am

siuksliadeze solution (http://forum.opencart.com/viewtopic.php ... 20#p114659) works on Version 1.5.2.1

Newbie

Posts

Joined
Thu May 24, 2012 4:30 am

Post by Lao » Sun Feb 03, 2013 11:06 pm

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

I'm using Open Cart 1.5.4.1 on http://www.importpieseauto.ro


User avatar
Lao
Active Member

Posts

Joined
Tue Nov 23, 2010 3:31 pm
Location - Craiova, Romania

Post by Lao » Tue Feb 05, 2013 3:51 am

Anyone??!

I'm using Open Cart 1.5.4.1 on http://www.importpieseauto.ro


User avatar
Lao
Active Member

Posts

Joined
Tue Nov 23, 2010 3:31 pm
Location - Craiova, Romania
Who is online

Users browsing this forum: No registered users and 82 guests