X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Displaying watermarks on product images (https://forum.x-cart.com/showthread.php?t=57635)

eleven 01-20-2011 08:32 AM

Displaying watermarks on product images
 
I couldn't find an easy mod to display watermarks on product images, so I came up with a bit of a hack to do it.

PLEASE NOTE:
- It will only work if you store your images on the filesystem.
- If you use different images depending on the product variants this will NOT work for you.
- Only tested on v4.3.1 on a somewhat basic site
- Use at your own risk.

Step 1: Copy this script and put it in the root (tweak as needed)

<?php
// this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
// where watermark.png or watermark.gif is a mostly transparent png or gif image with the watermark - goes in the same directory as this script
// where this script is named picture.php
// call this script with an image tag
// <img src="/picture.php?path=T/productpic.png">
$basebpath = "http://www.domain.com/cart/images/";

$imagesource = $basebpath . $_GET['path'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
if (!$image) die();
//$watermark = @imagecreatefromgif('watermark.gif'); // uncomment to use a gif
$watermark = @imagecreatefrompng('watermark.png'); // comment to use a gif
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2); // tweak this to change the location of the watermark
$startheight = (($imageheight - $watermarkheight)/2); // tweak this to change the location of the watermark
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>



Step 2: Edit /cart/skin1/product_thumbnail.tpl

Replace the line (this is the hack because the _t breaks the variant images javascript):
{if $id ne ''} id="{$id}"{/if} src="
with:
{if $id ne ''} id="{$id}_t"{/if} src="

Replace this line:
{$tmbn_url|amp}
with:
{$tmbn_url|amp|replace:'/cart/images/':'/picture.php?path='}

Learner 01-25-2011 12:21 AM

Re: Displaying watermarks on product images
 
Hi,
Thanks for your codes.Now is it possible to right click protected and drag and drop image in a folder in order to avoid image saving??

eleven 01-25-2011 06:23 AM

Re: Displaying watermarks on product images
 
you can add this to the <body> tag to right-click protect:
oncontextmenu="return false;"

There's really no way to stop someone from saving a picture from any site. If you can see it you can take a screen capture.

minfinger 04-24-2011 02:22 PM

Re: Displaying watermarks on product images
 
Hey I was trying this on 4.3.2 and I'm not having any results.

Is there some kind of change between 4.3.1 & 4.3.2 that would affect this?

minfinger 04-24-2011 02:39 PM

Re: Displaying watermarks on product images
 
Nevermind, I got it. the /cart/images, needed to be /images for me in the thumbnail file.

I do however want this on my detailed images as well. Is this possible?

eleven 04-24-2011 05:52 PM

Re: Displaying watermarks on product images
 
It should be possible with the detailed images. Off the top of my head, try looking at /skin1/modules/Detailed-Product_Images/product_images.tpl.

minfinger 04-24-2011 06:45 PM

Re: Displaying watermarks on product images
 
Thanks. I was looking for it, but couldn't remember where it was :D I'll give it a shot and post what I have.

My clients product photos appears to be landing on scam sites.

minfinger 04-24-2011 09:11 PM

Re: Displaying watermarks on product images
 
Well I tried a few things, but I'm not getting anywhere. I'll try again tomorrow.

minfinger 06-01-2011 04:19 PM

Re: Displaying watermarks on product images
 
I never could figure out how to get the watermark on the extra images.


All times are GMT -8. The time now is 06:51 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.