Post by NewUser » Wed Nov 04, 2009 5:54 am

hi i got all types of errors trying to add this watermark :D
url: http://liwzy.isgreat.org/watermark.png

please someone give the code cuz i can`t figure where exatly to put the image path
cuz i get no "url acces" error ... free host .. or is just not showing.. ???

User avatar
New member

Posts

Joined
Tue Nov 03, 2009 2:48 am

Post by ThePath » Mon Nov 09, 2009 6:28 pm

Check your config.php is that got the right image path in it?

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by decavolt » Thu Nov 19, 2009 7:13 am

I've just enabled watermarks and they are working, but the system already had a few thousand products entered. Is it possible to watermark existing images, and to do so with an actual watermark rather than just a div overlay?

Newbie

Posts

Joined
Tue Aug 18, 2009 9:35 am

Post by acidline » Tue Nov 24, 2009 3:55 pm

Is it possible to watermark existing images,
Just delete yout images cache directory ...
and to do so with an actual watermark rather than just a div overlay
isn't a watermark, with a right click, I can backup the image without the watermark, I think it's a bad idea :o

Nicolas

Newbie

Posts

Joined
Fri Aug 01, 2008 8:16 pm

Post by decavolt » Wed Nov 25, 2009 12:39 am

Wow, I'll just remove the cache. Great - thank you.
acidline wrote:
and to do so with an actual watermark rather than just a div overlay
isn't a watermark, with a right click, I can backup the image without the watermark, I think it's a bad idea :o
Exactly.

Newbie

Posts

Joined
Tue Aug 18, 2009 9:35 am

Post by dedurus » Mon Feb 01, 2010 6:19 am

For those that need to position the watermark on the center of the image, try this:


1. open system/library/image.php, and around line 85 find this code:

Code: Select all

 public function watermark($file, $position = 'bottomright') {
        //$watermark = $this->create($file);
		$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']) * 0.2);
                $watermark_pos_y = $this->info['height'] * 0.2;
                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;
        }

and replace it with the following code:

Code: Select all

public function watermark($file, $position = 'bottomright') {
        //$watermark = $this->create($file);
		$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']) * 0.2);
                $watermark_pos_y = $this->info['height'] * 0.2;
                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;
        }

2. open file system/helper/image.php and find this code (around line 12):

Code: Select all

$image->watermark(HTTP_IMAGE . 'watermark.png', 'bootomright');
and replace it with the following:

Code: Select all

$image->watermark(HTTP_IMAGE . 'watermark.png', 'center');
Works for me fine, even for thumbnails ;)

Newbie

Posts

Joined
Tue Dec 29, 2009 11:59 pm

Post by kia_hm » Sat Oct 09, 2010 6:52 pm

I am sorry, I didn't follow you since I am a novice OC user.
Can someone tells me where do I need to add this code, and how to active it.
cheers,

New member

Posts

Joined
Wed Sep 22, 2010 3:14 pm

Post by siuksliadeze » Fri Nov 26, 2010 12:13 am

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.
Last edited by siuksliadeze on Fri Nov 26, 2010 3:33 am, edited 2 times in total.

Newbie

Posts

Joined
Fri Nov 12, 2010 8:10 pm

Post by andrew222 » Fri Nov 26, 2010 1:42 am

Many thanks for putting the info together siuksliadeze. I'll be starting on this soon and also got a little confused following the thread ;)

New member

Posts

Joined
Wed Nov 17, 2010 12:30 pm

Post by t12industries » Fri Feb 18, 2011 11:45 am

Thanks for the clear instructions siukskiadaze.

This is a great mod!

Newbie

Posts

Joined
Sun Feb 06, 2011 9:20 am

Post by moreno13 » Fri Feb 18, 2011 2:26 pm

How to add the watermark image to all images
I like to add the mark to all images sizes can that be possible?

I using 1.4.9.2
Thank you
to all the experts who take the time to read this post
God Bless you all.
nice work Opencart team

New member

Posts

Joined
Thu Sep 30, 2010 10:02 am

Post by siuksliadeze » Mon Feb 21, 2011 8:06 pm

moreno13 wrote:How to add the watermark image to all images
I like to add the mark to all images sizes can that be possible?

I using 1.4.9.2
Thank you
to all the experts who take the time to read this post
God Bless you all.
nice work Opencart team
That's super easy, either put 0's in IF statement or just drop the IF statement, i.e. instead of this piece of code

Code: Select all

if ($width > 400 || $height > 300) {   
$image->watermark(DIR_IMAGE . 'watermark.png', 'center');    
}
use

Code: Select all

$image->watermark(DIR_IMAGE . 'watermark.png', 'center'); 

Newbie

Posts

Joined
Fri Nov 12, 2010 8:10 pm

Post by arkarwmh » Sun Mar 20, 2011 7:22 am

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

User avatar
Newbie

Posts

Joined
Sun Mar 20, 2011 7:00 am

Post by adityamenon » Tue Apr 05, 2011 9:01 pm

siuksliadeze, thanks a million! I'm using this on a new store - Fitutex (traditional Indian ethnic wear) - the best part is, since the source of the watermark in .png, I can have some text-effects on the copyright notice, and that integrates with the new generated image directly (well almost, this side-effect is not perfect)! This is definitely much more convenient that hacking at every image in Photoshop before upload :)

The only issue I noticed was, if you upload a PNG 24 file, it does not save properly. The transparency is lost, and some additional disturbance is getting added to the image. But PNG 8 files work fine.

Thanks once again...

Newbie

Posts

Joined
Mon Mar 21, 2011 9:09 am

Post by zborek » Tue Apr 12, 2011 4:23 am

siuksliadeze thanks a lot!
It's working great on 1.4.8 too.

This is only working method to fix watermark on Opencart 1.4.8 - I tested many, many "tips and tricks" and only this give my satisfaction.
In 3 minutes - super :)

Best regards!

PS
in any case you don't forget to backup files from the topic before mod ;)

Newbie

Posts

Joined
Tue Apr 12, 2011 4:13 am

Post by dunks » Thu Apr 21, 2011 7:21 pm

thanks a lot ..

work on 1.4.9

Ingat Gadget, Ingat DroidLime https://www.droidlime.com/


User avatar
Active Member

Posts

Joined
Wed Apr 20, 2011 1:19 pm
Location - Jakarta - Indonesia

Post by FabioSwiss » Thu May 05, 2011 4:48 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.

I haven't tried it yet, but does it add the watermark text on every images (thumbnails, and big images), or just on the "pop-up product images"? Can I choose the size of images I want to be watermarked?

Thanks!

Newbie

Posts

Joined
Fri Sep 17, 2010 4:06 am

Post by ebuybeauty » Mon May 09, 2011 4:44 pm

I have met the same problem, i want the products images with watermark when they are zoomed. but i don't know how to do it

http://www.shourouk.net


Newbie

Posts

Joined
Mon May 09, 2011 4:33 pm


Post by FabioSwiss » Mon May 09, 2011 5:05 pm

ebuybeauty wrote:I have met the same problem, i want the products images with watermark when they are zoomed. but i don't know how to do it

I did it (or better, someone did it for me :-)). This is the code:

Code: Select all

      $fontfile = '/path-of-your-font/yourfont.TTF';
		$rotation = 30;
		$width = imagesx($this->image);
		$height = imagesy($this->image);
		$statement = 'Copyright by.......;
		if ($width > 500) {
			$fontsize = 50;
		} else if ($width > 200) {
			$fontsize = 15;
		} else if ($width > 50) {
			$fontsize = 8;
		} else {
			$fontsize = 0;
		}

		if ($fontsize>0) {

			//imagealphablending($this->image, true);
			//imagesavealpha($this->image, true);
			$wmColor = imagecolorallocatealpha($this->image, 150, 150, 150, 90);
			$wmDim = imagettfbbox  ( $fontsize, $rotation, $fontfile , $statement );

			imagettftext( $this->image  , $fontsize, $rotation, ($width - $wmDim[2])/2, ($height - $wmDim[3])/2 , $wmColor, '/path-of-your-font/yourfont.TTF'  , $statement  );
Like this, the text size is customizable based on image width (when I don't want the watermark I just write "0" on fontsize). I had to add a font to the server, because the default one had a maximun size of 5. I had to add a rotation too!

Hope this can help!

Newbie

Posts

Joined
Fri Sep 17, 2010 4:06 am

Post by turantekin » Wed Jun 01, 2011 7:01 pm

[quote="siuksliadeze"]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.

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

I Love Open Cart : )
http://www.stabilitees.com


Newbie

Posts

Joined
Fri Apr 22, 2011 7:23 am
Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 75 guests