[How to] Add watermark to image???
Posted: Mon Jun 28, 2010 1:42 pm
I found this function in system/library/image.php.
How to use it???
Regards.
Amdev
How to use it???
Regards.
Amdev
OpenCart Community Forum - Discuss shopping cart and e-commerce solutions.
https://forum.opencart.com/
Code: Select all
/catalog/model/tool/image.php file
Code: Select all
$image = new Image(DIR_IMAGE . $old_image);
Code: Select all
$image->resize($width, $height);
Code: Select all
$image->watermark(DIR_IMAGE . 'path/to/image/in/image/folder.png', 'position-name-here');
Me too, it didn't work.Melanie wrote:Hi,
I tried the above but it didn't work.
Im running v.1.48b
Any instructions for enabling the watermark feature?
Thanks,
Melanie
Code: Select all
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->watermark(DIR_IMAGE . 'data/watermark.png', 'topleft');
$image->save(DIR_IMAGE . $new_image);
Code: Select all
/system/library/image.php
Code: Select all
imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40);
Code: Select all
imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height);
Code: Select all
/image/cache/data/
Thanks JAY6390 so much for ur advice.JAY6390 wrote:Seems there was an error in the watermark code
Edit the filefind this lineCode: Select all
/system/library/image.php
replace with this lineCode: Select all
imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40);
Note you will need to delete all of your images located inCode: Select all
imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height);
to get the images recreated for your cacheCode: Select all
/image/cache/data/
Yes, i did it.JAY6390 wrote:Have you create a file called watermark.png with an image in the /image/data/ folder? My watermark was actually a jpg file (my avatar off here to be precise)
Code: Select all
imagecopymerge($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height,75);
Thanks,lillolollo wrote:For png wtm you must use imagecopymerge not imagecopy
Code: Select all
imagecopymerge($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height,75);
Image of watermark must be .jpg.dramony wrote:any screen shots?
Hello, I am a litle bit confused. I am reading that the watermark image has to have the same extension as the images. But I am also reading to use a png to get a transaparent watermarkamdev wrote: Image of watermark must be .jpg.
Because image in cache/data/ are all of .jpg
so, don't use imagecopymerge() function.
Code: Select all
if ($extension == 'jpeg' || $extension == 'jpg') {
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.