There is an easy way to automatically integrate WordPress Watermark on your Content Images. You just need a small script and an additional line in your .htaccess
Disclaimer
If you need WordPress help, you can find advice on wordpress.stackexchange.com, where I post regularly as fischi. I do not provide support here.
Save the script as „watermark.php“. Feel free to alter the parameters, every parameter for the watermarks is explained in the code.
The code for creating the Watermark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
<?php /********************************************** *** Automatic Watermark for Content Images *** *********************************************** *** *** *** to be used on any CMS. *** *** do not forget to alter your .htaccess *** *** to rewrite the image paths *** *** to this watermark.php *** *** *** *** Author: Thomas 'Fischi!' Fischer, 2010 *** *** based on an idea by webmastersucks.com *** *** http://www.fischi.cc *** *** *** **********************************************/ // set the header to jpg output, and get the url of the image wth the src parameter. header('Content-type: image/jpeg'); $src = $_GET['src']; // Check the Imagesize - and insert the right watermark for the right sizes. // Here on my blog: Thumbnails are processed with a frame and shadow, // small images with a watermark where just my logo is shown // and big images with the logo and url. other small images are left untouched. $origsize = getimagesize($src); // set the right watermarks if (eregi("120x120", $src)) { $watermark = imagecreatefrompng('http://www.fischi.cc/wp-content/themes/fischi/images/frame.png'); } else if ($origsize[0] < 160 && $origsize[1] < 160) { $skip = "true"; } else if ($origsize[0] < 400) { $watermark = imagecreatefrompng('http://www.fischi.cc/wp-content/themes/fischi/images/justhead.png'); } else { $watermark = imagecreatefrompng('http://www.fischi.cc/wp-content/themes/fischi/images/watermark.png'); } // create the temporary image. alter the if parameters, // if you don't want to process some images, for example transparent png's. // of course, there should not be too much trouble with content images. if(eregi('.gif',$src)) { $image = imagecreatefromgif($src); } elseif(eregi('.jpeg',$src)||eregi('.jpg',$src)) { $image = imagecreatefromjpeg($src); } elseif(eregi('.png',$src)) { $image = imagecreatefrompng($src); } else { exit("Your image is not a gif, jpeg or png image. Sorry."); } // just process the image, if a watermark has to be integrated. if ($skip != "true") { // watermark sizes. strongly recommended to be computed, not set statically. $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); // get the position of the watermark. calculated from the size of the original image, // minus the size of the watermark. feel free to adjust these parameters. // for example, if you want the watermark to be displayed on the top left, // just set them both to zero. the last parameter (-0) gives you the option of leaving // a space between the end of the image and the watermark (kind of the margin in css) $dest_x = $origsize[0] - $watermark_width - 0; $dest_y = $origsize[1] - $watermark_height - 0; // putting the watermark on the original image imagecolortransparent($watermark, imagecolorat($watermark,0,0)); imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height); } // direct output of the image, as jpg. adjust the last parameter to set the quality. imagejpeg($image, "", 95); // cleaning out the temporary files. imagedestroy($image); imagedestroy($watermark); ?> |
Now you have to alter your .htaccess: Insert the line below. This example is to be used for WordPress, if you don’t want to use a WordPress Watermark Plugin or if you can’t find one that fulfills your needs.
Of course, this script can be used with any other CMS as well: it ddoesn’t matter if it’s Wrdpress, Joomla, SixCMS, Drupal or anything else. The trick is to redirect the images from your upload directory to the watermark.php with a regular expression, and pass the source of the image on with a GET parameter.
ATTENTION! Please do not use this script on every image, because the images in your templates should not be affected by an automatic watermark integration. If you want to do this on purpose, no problem. But it makes no sense to have a Watermark on your icons 😉
The code for enabling WordPress Watermark in your system
1 |
RewriteRule ^(.*)wp-content/uploads/(.*) $1watermark.php?src=wp-content/uploads/$2 |
Have Fun!
Sometimes it pays off to know PHP, and not just making a collection of WordPress Plugins 🙂 I think most WordPress Watermark Plugins are to inflexible or broken, and if you integrate the Watermark on the upload, you have no possibility to change them, for example if your customerr changes his logo. If you integrate the Watermark on the fly, you should not have a problem with that.
Another plus: You are not dependent on the ongoing improvement of a specific WordPress Watermark Plugin!
Have a nice Day,
fischi.
This was a long time ago… My page looked like this:
To be able to choose an online gambling site that can be trustworthy and
provide the best service, you must know and know first
with the betting website that you will choose. Also make sure
the web betting that you find meets the requirements as the best online gambling site.
Do Research in Forums
The least difficult way to make sure you can safely use a betting site or not is to learn or participate in discussions with people in internet gambling forums.
All those in the betting forum are usually experienced players and
know which wagering sites provides the best service.
Inquire the Player
If speaking about in a community forum is difficult that you should do or do not
know which forum you can visit to do research, we suggest that you directly ask the more experienced players.
In addition you can also request tips and tricks on the best strategies that may be applied in the game
Thanks for this code, but how do i exclude my site logos from getting watermarked?
Thank you!
Hello,
this code add watermark to all images from wp-content /uploads .. is there any possibility to filter ? like anyname_logo.jpg should not apply this etc
Thank you
Good, thanks
Thank you for the good writeup. It actually used to be a enjoyment account it.
Glance complex to more delivered agreeable from you! However, how could we keep up a correspondence?
Where we can put water mark code in wordpress?
This event may appear from a normal spin of the reels, or it could occur from the
Glowing 7 Reward.
It’s an awesome piece of writing designed for all the online people; they will get advantage from it I am sure.
However, after one donation, you arre able to donate again only after a couple of months when your body has regained the donated blood.
Then write the way appears to be tto yoou and takme notice as
you lay the caards to learn more abojt yourself watching the
method that you will discover the hidrden lesson. Over the arrival months I’ll
be writing some articles revealing the tjps for public relations (everything a journalist
won’t would like you to know.
Does this work with woocommerce products? and how do you go by applying to product images only. Excluding all non-product images?
Hi, this version does not really work for filtering, as all media is processed.
You have a few possibilities – if your productimages are a specific size, you can create a Watermark for those, and not for the other pictures. You will need to have something to identify which picture is a product picture, then this is no problem.
This is plugin, but how can i do without plugin?
Sorry I saw your comment just now. Do you still need help?
hello fischi
i am create watermark.php file and copy source to file
and create empty png and watermark png and set to watermark.php
and set rewrite code to htaccess
but test it . and not show image in content. my image is broken .
my image is default wordpress: wp-content/uploads
test in firefox show error:
The image “http://mysite.com/wp-content/uploads/2012/04/apple-firstquarter-earnings-report-2012.jpg” cannot be displayed because it contains errors.
please help me for solve problem
thank you
Hi,
I have the same problem. Do you have find a issue ?
Thank you very much.
See you
Bye
Stéphanie
Thank you!
How do i tell it to put the watermark on two different directories?
Hi Monica!
Sorry for the delayed answer, but i was on internet and phonefree holiday 🙂
Do i understand that correctly, that you want to add another directory to add the watermark?
you already have http://www.example.com/wp-content/uploads done with watermarks, so if you want to have http://www.example.com/tryme to have the watermark, you have to add this line to your .htaccess file:
RewriteRule ^(.*)tryme/(.*) $1watermark.php?src=tryme/$2
now you are all set!
cheers
fischi