Jump to content
ced

Adding a watermark on image

Recommended Posts

ced

Hi,

I've got it working on my 2.3.8 site with a simple .htaccess file.

 

How adding a watermark on images ?

Watermark generation on the fly

1- First, you need to create your one watermark.png image with your favorite image editor and simply call it "watermark.png".

 

2- Create a watermark.php file and copy/past this code:

 

<?php

 // loads a png, jpeg or gif image from the given file name
 function imagecreatefromfile($image_path) {
   // retrieve the type of the provided image file
   list($width, $height, $image_type) = getimagesize($image_path);

   // select the appropriate imagecreatefrom* function based on the determined
   // image type
   switch ($image_type)
   {
     case IMAGETYPE_GIF: return imagecreatefromgif($image_path); break;
     case IMAGETYPE_JPEG: return imagecreatefromjpeg($image_path); break;
     case IMAGETYPE_PNG: return imagecreatefrompng($image_path); break;
     default: return ''; break;
   }
 }

 // load source image to memory
 $image = imagecreatefromfile($_GET['image']);
 if (!$image) die('Unable to open image');

 // load watermark to memory
 $watermark = imagecreatefromfile($_GET['watermark']);
 if (!$image) die('Unable to open watermark');

 // calculate the position of the watermark in the output image (the
 // watermark shall be placed in the lower right corner)
 $watermark_pos_x = imagesx($image) - imagesx($watermark) - 8;
 $watermark_pos_y = imagesy($image) - imagesy($watermark) - 10;

 // merge the source image and the watermark
 imagecopy($image, $watermark,  $watermark_pos_x, $watermark_pos_y, 0, 0,
   imagesx($watermark), imagesy($watermark));

 // output watermarked image to browser
 header('Content-Type: image/jpeg');
 imagejpeg($image, '', 100);  // use best image quality (100)

 // remove the images from memory
 imagedestroy($image);
 imagedestroy($watermark);

?>

 

Save it as "watermark.php".

 

3- Create a ".htaccess" file and copy/past this code:

 

RewriteEngine on
RewriteRule ^([^tn].*\.(gif|jpg|png))$ /images/jreviews/watermark.php?image=$1&watermark=watermark.png [NC]

If you are running your website in a subfolder, you need to put the entire path, ie. /yoursubfolder/images/...

 

The "[^tn]" will exclude the thumbnails from being watermarked; if you want it, just remove it.

 

4- Then upload with your ftp the 3 files, watermark.png, watermark.php and .htaccess in your www.yoursite/images/jreviews directory (not the tn folder).

 

Check your site, eventually press F5 to empty the cache and enjoy.

 

Ced

 

For further informations, script source from http://www.htmlguard.com/articles/using-htaccess-to-mask-watermark-php-calls/

 

 

Share this post


Link to post
Christian Lin

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Christian Lin

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Steve Carter

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
netfly

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
corwin

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Marius Carneala

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Marino

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Marino

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Janz

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Lars Noack

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
dealio

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Mattia Bondrano

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
ced

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Mattia Bondrano

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
corwin

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
neeraj khatri

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Patrick the Beer Man

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Andreas Behrens

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.