Author Topic: watermark using .htacces files  (Read 19152 times)

Luciffere

  • Jr. Member
  • **
  • Posts: 66
  • Web Design de Calitate
    • Web Design de Calitate
watermark using .htacces files
« on: November 03, 2008, 18:47:28 pm »
1. make a file .htaccess in /components/com_virtuemart/shop_images/product/ with the code:
 
Code: [Select]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif|jpeg|jpg|png)$ /components/com_virtuemart/shop_image/product/watermark.php [QSA,NC]

2. make a file watermark.php in /components/com_virtuemart/shop_images/product/ with code:
Code: [Select]
<?php
// watermark.php

// Path the the requested file
$path $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];

// Load the requested image
$image imagecreatefromstring(file_get_contents($path));
$w imagesx($image);
$h imagesy($image);

// Load the watermark image
$watermark imagecreatefrompng('watermark.png');
$ww imagesx($watermark);
$wh imagesy($watermark);

// Merge watermark upon the original image (centred)
imagecopy($image$watermark, (($w/2)-($ww/2)), (($h/2)-($wh/2)), 00$ww$wh);

// Send the image
header('Content-type: image/jpeg');
imagejpeg($image,null,95);
exit();
?>


3. Create your custom watermark.png files and save in /components/com_virtuemart/shop_image/product/

That's all...
Gift based on total order
Web design, logo, branding, joomla, virtuemart, flash. Portofoliu web design: http://www.luciffere.ro/portofoliu.html

Paolo Di Canio

  • Beginner
  • *
  • Posts: 1
Re: watermark using .htacces files
« Reply #1 on: December 21, 2008, 00:52:04 am »
This is brilliant, very clever thank you.

The only issue I have is "additional images" not showing at all from FileManager.

Please can someone adjust the watermark.php here so this will also work for additional images.

shoulders

  • Beginner
  • *
  • Posts: 16
Re: watermark using .htacces files
« Reply #2 on: February 26, 2009, 15:05:20 pm »
this is a brilliant trick and has saved me hours of work.

I would like some easy instructions so i can have a play about with the location and resizing options on the water mark so i can use one watermark on large and small images and maybe put my website on an angle like you see on ebay all the time.

Thanks

shoulders

shoulders

  • Beginner
  • *
  • Posts: 16
Re: watermark using .htacces files
« Reply #3 on: February 26, 2009, 19:07:41 pm »
I have dug around on the internet and have found these 2 sites.

http://baglan.web.tr/watermarking-php

this has a improved version of this script where you do not even have to enter file locations. Also he has done a cached version of this script.

I have also redone the watermark locations, you can either replace the one that is there or add them all.

Code: [Select]
// (top left)
imagecopy($image, $watermark, 0, 0, 0, 0, $ww, $wh);

// (top center)
imagecopy($image, $watermark, (($w/2)-($ww/2)), 0, 0, 0, $ww, $wh);

// (top right)
imagecopy($image, $watermark, $w-$ww, 0, 0, 0, $ww, $wh);

// (left centre)
imagecopy($image, $watermark, 0, (($h/2)-($wh/2)), 0, 0, $ww, $wh);

// (centre)
imagecopy($image, $watermark, (($w/2)-($ww/2)), (($h/2)-($wh/2)), 0, 0, $ww, $wh);

// (right centre)
imagecopy($image, $watermark, $w-$ww, (($h/2)-($wh/2)), 0, 0, $ww, $wh);

// (bottom left)
imagecopy($image, $watermark, 0, $h-$wh, 0, 0, $ww, $wh);

// (bottom center)
imagecopy($image, $watermark, (($w/2)-($ww/2)), (($h)-($wh)), 0, 0, $ww, $wh);

// (bottom right)
imagecopy($image, $watermark, $w-$ww, $h-$wh, 0, 0, $ww, $wh);

The second site is a tutorial on an old version but is a good read to help out in altering the script if needed.

http://www.sitepoint.com/article/watermark-images-php/


vm_user

  • Jr. Member
  • **
  • Posts: 156
Re: watermark using .htacces files
« Reply #4 on: February 26, 2009, 20:33:17 pm »
I just tried the first method on my site and all my product images turned into the dreaded red cross! I had to back out of it quickly to restore them.

Any ideas?
Joomla 1.5.15, VM 1.1.4

shoulders

  • Beginner
  • *
  • Posts: 16
Re: watermark using .htacces files
« Reply #5 on: February 26, 2009, 20:42:51 pm »
if you are using the code from this page at the top:

try using the code on the first link i gave, or you can check that the file location in the htaccess file is correct (check slashes etc) and that you have GD2 libaries installed along with mod rewrite (if you have pretty joomla urls you have rewrite on)

the red cross thing happend to me and it was that i had not altered the path in the htaccess file

also do not experiment with your virtuemart pictures, just use any folder and alter the locations (or not) as needed. for testing i did this and used direct links in my web browser to check they worked.

shoulders

vm_user

  • Jr. Member
  • **
  • Posts: 156
Re: watermark using .htacces files
« Reply #6 on: February 27, 2009, 12:20:41 pm »
OK, thanks, I'll check on the GD2 libraries.

Will this work on vm 1.0.x?
Joomla 1.5.15, VM 1.1.4

shoulders

  • Beginner
  • *
  • Posts: 16
Re: watermark using .htacces files
« Reply #7 on: February 27, 2009, 13:37:26 pm »
this trick is independant of virtuemart, but if not, you should be using the latest version of joomla 1.5.9 and the latest VM 1.1.3.

I also read that some versions of php stop this working, dont know why. so it could be this. glitch in the matrix maybe.

shoulders

vm_user

  • Jr. Member
  • **
  • Posts: 156
Re: watermark using .htacces files
« Reply #8 on: February 27, 2009, 17:19:34 pm »

I also read that some versions of php stop this working, dont know why. so it could be this. glitch in the matrix maybe.


Aah, that could be it - my ISP implemented SU-PHP a few months ago.
Joomla 1.5.15, VM 1.1.4

shoulders

  • Beginner
  • *
  • Posts: 16
Re: watermark using .htacces files
« Reply #9 on: February 27, 2009, 17:44:41 pm »
hi mate,

SU-PHP is a good thing, but maybe the folders you are putting the script in have permmissinons of 777 on them in which case they might not run. 755 is the maximum.

Mingus

  • Beginner
  • *
  • Posts: 11
    • Neting - realizzazione siti
Re: watermark using .htacces files
« Reply #10 on: February 19, 2013, 11:16:42 am »
Hi
I'been able to apply your solution, but I would like to exclude from the rewrite condition the subdirectory 'resized' as I do not want to watermark the generated thumbs, but only the normal image. Do you have any suggestion? Thank you

Luca

ODIS

  • Beginner
  • *
  • Posts: 2
Re: watermark using .htacces files
« Reply #11 on: March 07, 2013, 11:19:15 am »
Hello
you just need to modify .htaccess to this

Code: [Select]
RewriteRule ^(resized)($|/) - [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif|jpeg|jpg|png)$ watermark.php [QSA,NC]

first line of the code declare that it'll exclude the resized folder