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
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)2. Add following piece of codes AFTER.Code: Select all
if ($extension == 'jpeg' || $extension == 'jpg') {
Enjoy!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.
Regards,
Arkar
arkarwmh@gmail.com
Is there any way to apply this only to images bigger than 200px?
The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.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)
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.
you can use do the following:
Code: Select all
if ($width < 900 || $height < 250) {
$image->watermark(DIR_IMAGE . 'watermark.png', 'center');
}
Kulsha wrote:The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.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)
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.
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: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') { $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); }
4. Second file to edit is catalog/model/tool/image.phpCode: 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); }
Go to line 27 and you will see the follwing line:Right after this line add the following code:Code: Select all
$image = new Image(DIR_IMAGE . $old_image);
In the code above you can define desired position of the watermark (topleft, topright, bottomleft, bottomright or center).Code: Select all
if ($width > 400 || $height > 300) { $image->watermark(DIR_IMAGE . 'watermark.png', '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....
is it possible to put the watermark in the center thank youarkarwmh 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)2. Add following piece of codes AFTER.Code: Select all
if ($extension == 'jpeg' || $extension == 'jpg') {
Enjoy!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.
Regards,
Arkar
arkarwmh@gmail.com
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.
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
it just marked not allow promotional logo / words.
http://www.google.com/support/merchants ... wer=188484
Your images may not contain promotional messages of any kind, including watermarks or promotional text
Your images may not contain promotional messages of any kind, including watermarks or promotional text
free shipping is not allowed...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.
siuksliadeze solution (http://forum.opencart.com/viewtopic.php ... 20#p114659) works on Version 1.5.2.1
Hello all!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:The previous detailed step by step instructions on page 2 by siuksliadeze work perfectly in version 1.5.1.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)
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.
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) {
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
Who is online
Users browsing this forum: Baidu [Spider], Google [Bot] and 65 guests