PHP Classes

Protect Image: Put transparent watermark text on images

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 743 This week: 1All time: 4,512 This week: 560Up
Version License PHP version Categories
protect-image 0.2MIT/X Consortium ...5PHP 5, Graphics
Description 

Author

This class can put transparent watermark text on images.

It can create an image that is the result of a given image with a watermark text rendered on top of the original image.

The transparency level of the watermark text area, the position, the font and the color of the watermark text are configurable parameters.

Picture of Karl Holz
  Performance   Level  
Name: Karl Holz <contact>
Classes: 14 packages by
Country: Canada Canada
Age: 43
All time rank: 44918 in Canada Canada
Week rank: 106 Up3 in Canada Canada Up
Innovation award
Innovation award
Nominee: 9x

Example

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$file='oldboxes.png';


$test='string';
//$test='save';
//$test='encode';
//$test='invalid_file';
//$test='encode_html';
//$test='invalid_img';


require_once 'protectimg.class.php';

switch (
$test) {
  case
'string':
  
$img=new protect_img($file);
  
$img->add_watermark="Name Here";
  
$img->add_watermark="<name@email.com>";
  
$img->add_watermark="http://www.website.com";
  
// add watermark text first, width guessing might not work out as you want,
   // just play around to get the proper width to meet your needs
  
$img->watermark_width=300;
  
$img->watermark_font=8;
  
/**
$img->watermark_alpha=46;
$img->watermark_font=5;
$img->watermark_start_x=20;
$img->watermark_start_y=180;
$img->watermark_border=8;
$img->watermark_height=70;
$img->watermark_colors=array('0xABCDEF', '0x012345');
 */
  
$img->water_mark();
  
$img->send_img();
  break;
  case
'invalid_file':
  
$img=new protect_img('$invalid');
  break;
  case
'invalid_img':
  
$invalid='/var/log/apache2/error.log';
  
$img=new protect_img($invalid);
  break;
  case
'encode': // return encoded string, for storing in a db, after water_mark
  
header("Content-type: text/plain");
  
$img=new protect_img($file);
  
//$img->add_watermark=$mark;
  
$img->add_watermark="Name Here";
  
$img->add_watermark="<name@email.com>";
  
$img->add_watermark="http://www.website.com";
  
// add watermark text first, width guessing might not work out as you want,
   // just play around to get the proper width to meet your needs
  
$img->watermark_width=300;
  
$img->watermark_font=8;
  
$img->encode_img();
   echo
$img->encoded;
   exit();
  break;
  case
'encode_html': // encode image, after water_mark
  
header("Content-type: text/html");
  
$img=new protect_img($file);
  
//$img->add_watermark=$mark;
  
$img->add_watermark="Name Here";
  
$img->add_watermark="<name@email.com>";
  
$img->add_watermark="http://www.website.com";
  
// add watermark text first, width guessing might not work out as you want,
   // just play around to get the proper width to meet your needs
  
$img->watermark_width=300;
  
$img->watermark_font=8;
  
$img->water_mark();
  
$img->encode_img();
   echo
$img->encode_img_html();
  break;
  case
'save':
  
$img=new protect_img($file);
  
//$img->add_watermark=$mark;
  
$img->add_watermark="Name Here";
  
$img->add_watermark="<name@email.com>";
  
$img->add_watermark="http://www.website.com";
  
// add watermark text first, width guessing might not work out as you want,
   // just play around to get the proper width to meet your needs
  
$img->watermark_width=300;
  
$img->watermark_font=8;
  
$img->water_mark();
  
$img->save_img();

  
$file= str_replace(basename($_SERVER['SCRIPT_NAME']), $img->save ,$_SERVER['SCRIPT_NAME']);
  
header("Content-type: text/html");
   echo
'<a href="http://'.$_SERVER['HTTP_HOST'].$file.'" >'.$file.'</a> saved';
  break;
}
?>



Screenshots  
  • after.jpg
  • before.jpg
  Files folder image Files  
File Role Description
Accessible without login Plain text file img.php Example Example script
Accessible without login Image file oldboxes.png Photo test img input
Plain text file protectimg.class.php Class protect image class
Accessible without login Plain text file tester.php Example this will test out the class, it's all setup within a case statement use the $test variable
Accessible without login Image file wmoldboxes.png.jpg Output test watermark output

 Version Control Unique User Downloads Download Rankings  
 57%
Total:743
This week:1
All time:4,512
This week:560Up