Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Displaying watermarks on product images

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 01-20-2011, 08:32 AM
 
eleven eleven is offline
 

Senior Member
  
Join Date: Nov 2002
Location: Charlotte, NC, USA
Posts: 118
 

Default 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='}
__________________
|| E L E V E N ||
Reply With Quote

The following user thanks eleven for this useful post:
am2003 (06-01-2011)
  #2  
Old 01-25-2011, 12:21 AM
 
Learner Learner is offline
 

X-Adept
  
Join Date: Dec 2008
Posts: 807
 

Default 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??
__________________
4.6.1 Platinum


Reply With Quote
  #3  
Old 01-25-2011, 06:23 AM
 
eleven eleven is offline
 

Senior Member
  
Join Date: Nov 2002
Location: Charlotte, NC, USA
Posts: 118
 

Default 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.
__________________
|| E L E V E N ||
Reply With Quote
  #4  
Old 04-24-2011, 02:22 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default 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?
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #5  
Old 04-24-2011, 02:39 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default 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?
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #6  
Old 04-24-2011, 05:52 PM
 
eleven eleven is offline
 

Senior Member
  
Join Date: Nov 2002
Location: Charlotte, NC, USA
Posts: 118
 

Default 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.
__________________
|| E L E V E N ||
Reply With Quote
  #7  
Old 04-24-2011, 06:45 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Displaying watermarks on product images

Thanks. I was looking for it, but couldn't remember where it was I'll give it a shot and post what I have.

My clients product photos appears to be landing on scam sites.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #8  
Old 04-24-2011, 09:11 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Displaying watermarks on product images

Well I tried a few things, but I'm not getting anywhere. I'll try again tomorrow.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #9  
Old 06-01-2011, 04:19 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Displaying watermarks on product images

I never could figure out how to get the watermark on the extra images.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:10 PM.

   

 
X-Cart forums © 2001-2020