Sunday, December 25, 2011

PHP Image Watermaek

To prevent quality images being stolen, we can use PHP to watermark web-images in popular formats like GIF/PNG/JPEG. We print a transparent gif-image on a jpeg-photo in this tutorial. For best results I prefer gif than png, because some png formats require extra functions to print a transparent image. We can convert this script to a batch-watermarker easily to watermark photo albums/galleries with multiple pictures by putting code in a loop or create a function.
Steps:
  1. Load both images
  2. Get size of both images
  3. Copy watermark to main image
  4. Print image to screen


PHP functions:
imagecreatefromgif
imagecreatefromjpeg
getimagesize
imagecopymerge
header
imagejpeg
imagedestroy


Watermark image:




Main image:




PHP Code:



Example images:

Watermarked image with 10% opacity

Watermarked image with 50% opacity

Watermarked image with 100% opacity

No comments:

Post a Comment