PHP Classes

I've changed to watermark function.

Recommend this page to a friend!

      Image Handling  >  All threads  >  I've changed to watermark function.  >  (Un) Subscribe thread alerts  
Subject:I've changed to watermark function.
Summary:Package rating comment
Messages:1
Author:Levent
Date:2012-03-18 00:46:01
 

Levent rated this package as follows:

Utility: Good
Consistency: Good
Examples: Good

  1. I've changed to watermark function.   Reply   Report abuse  
Picture of Levent Levent - 2012-03-18 00:46:01
I've changed to watermark function. Like this,


public function watermark($mark,$opac,$pos) {
if(file_exists($mark) && ($this->image != "")) {
$ext = strtolower(end(explode(".",$mark)));

switch($ext) {
case "jpg" :
case "jpeg" : $watermark = imagecreatefromjpeg($mark); break;
case "gif" : $watermark = imagecreatefromgif($mark); break;
case "png" : $watermark = imagecreatefrompng($mark); break;
}

$sourcefile_width=imagesx($this->image);
$sourcefile_height=imageSY($this->image);

list($watermark_width,$watermark_height) = getimagesize($mark);

$dest_x = ( $sourcefile_width / 2 ) - ( $watermark_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermark_height / 2 );

switch($pos)
{
//middle middle
case 0:
$dest_x = ( $sourcefile_width / 2 ) - ( $watermark_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermark_height / 2 );
break;

//top left
case 1:
$dest_x = 0;
$dest_y = 0;
break;

//top right
case 2:
$dest_x = $sourcefile_width - $watermark_width;
$dest_y = 0;
break;

//bottom right
case 3:
$dest_x = $sourcefile_width - $watermark_width;
$dest_y = $sourcefile_height - $watermark_height;
break;

//bottom left
case 4:
$dest_x = 0;
$dest_y = $sourcefile_height - $watermark_height;
break;

//top middle
case 5:
$dest_x = ( ( $sourcefile_width - $watermark_width ) / 2 );
$dest_y = 0;
break;

//middle right
case 6:
$dest_x = $sourcefile_width - $watermark_width;
$dest_y = ( $sourcefile_height / 2 ) - ( $watermark_height / 2 );
break;

//bottom middle
case 7:
$dest_x = ( ( $sourcefile_width - $watermark_width ) / 2 );
$dest_y = $sourcefile_height - $watermark_height;
break;

//middle left
case 8:
$dest_x = 0;
$dest_y = ( $sourcefile_height / 2 ) - ( $watermark_height / 2 );
break;
}

imagecopymerge($this->image,$watermark,$dest_x,$dest_y,0,0,$watermark_width,$watermark_height,$opac);
}
}