Post by perezosogato » Wed Sep 21, 2011 9:18 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
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 ?

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by rgtobr » Mon Oct 17, 2011 10:08 pm

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.

Newbie

Posts

Joined
Sat Oct 15, 2011 2:07 am

Post by paulosam » Sun Mar 10, 2013 1:31 am

I made new Watermark Module called "Samcholi Watermark".

It is very easy to use.

I recommend you to use it.

Regards.

User avatar
Newbie

Posts

Joined
Sun Mar 10, 2013 1:17 am
Location - New Delhi

Post by OSWorX » Thu Apr 04, 2013 11:43 pm

And I recommend this here: http://osworx.net/en/development/43-ope ... watermarks
Simply the easiest watermark module for OpenCart.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by storm-cloud » Tue Jun 23, 2015 10:47 pm

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?

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by jasonc310771 » Wed Oct 21, 2015 1:57 pm

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.

Active Member

Posts

Joined
Fri Mar 01, 2013 6:46 pm

Post by BettyeDth » Wed Oct 21, 2015 3:25 pm

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.

Egal wie du dich fühlst, steh auf, kleide dich an und zeige dich. hulle6.com


Newbie

Posts

Joined
Thu Oct 15, 2015 7:45 pm


Post by danncti » 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);

Newbie

Posts

Joined
Thu Apr 06, 2017 6:29 pm

Post by pla1829 » Sat Nov 18, 2017 2:47 am

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

New member

Posts

Joined
Sat Nov 22, 2014 12:16 pm
Who is online

Users browsing this forum: ryan1969 and 26 guests