note 77085 modified in function.imagealphablending by ronabop

From: Date: Tue, 26 Feb 2008 20:42:51 +0000
Subject: note 77085 modified in function.imagealphablending by ronabop
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136517@lists.php.net to get a copy of this message
I have create a little function for putting a watermark on any picture. Watermark can be png, with transparency, and the watermark can be placed anywhere on the image, using simple strings such as 'bottom-left', or 'center'. <? function imagelogo (&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h, $position='bottom-left') { imagealphablending($dst_image,true); imagealphablending($src_image,true); if ($position == 'random') { $position = rand(1,8); } switch ($position) { case 'top-right': case 'right-top': case 1: imagecopy($dst_image, $src_image, ($dst_w-$src_w), 0, 0, 0, $src_w, $src_h); break; case 'top-left': case 'left-top': case 2: imagecopy($dst_image, $src_image, 0, 0, 0, 0, $src_w, $src_h); break; case 'bottom-right': case 'right-bottom': case 3: imagecopy($dst_image, $src_image, ($dst_w-$src_w), ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'bottom-left': case 'left-bottom': case 4: imagecopy($dst_image, $src_image, 0 , ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'center': case 5: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; case 'top': case 6: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), 0, 0, 0, $src_w, $src_h); break; case 'bottom': case 7: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'left': case 8: imagecopy($dst_image, $src_image, 0, (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; case 'right': case 9: imagecopy($dst_image, $src_image, ($dst_w-$src_w), (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; } } // example: imagelogo($image, $watermark, imagesx($image), imagesy($image), imagesx($watermark), imagesy($watermark), 'random'); ?> --was-- I have create a little function for putting a watermark on any picture. Watermark can be png, with transparency, and the watermark can be placed anywhere on the image, using simple strings such as 'bottom-left', or 'center'. <? function imagelogo (&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h, $position='bottom-left') { imagealphablending($dst_image,true); imagealphablending($src_image,true); if ($position == 'random') { $position = rand(1,8); } switch ($position) { case 'top-right': case 'right-top': case 1: imagecopy($dst_image, $src_image, ($dst_w-$src_w), 0, 0, 0, $src_w, $src_h); break; case 'top-left': case 'left-top': case 2: imagecopy($dst_image, $src_image, 0, 0, 0, 0, $src_w, $src_h); break; case 'bottom-right': case 'right-bottom': case 3: imagecopy($dst_image, $src_image, ($dst_w-$src_w), ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'bottom-left': case 'left-bottom': case 4: imagecopy($dst_image, $src_image, 0 , ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'center': case 5: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; case 'top': case 5: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), 0, 0, 0, $src_w, $src_h); break; case 'bottom': case 6: imagecopy($dst_image, $src_image, (($dst_w/2)-($src_w/2)), ($dst_h-$src_h), 0, 0, $src_w, $src_h); break; case 'left': case 7: imagecopy($dst_image, $src_image, 0, (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; case 'right': case 8: imagecopy($dst_image, $src_image, ($dst_w-$src_w), (($dst_h/2)-($src_h/2)), 0, 0, $src_w, $src_h); break; } } // example: imagelogo($image, $watermark, imagesx($image), imagesy($image), imagesx($watermark), imagesy($watermark), 'random'); ?> http://php.net/manual/en/function.imagealphablending.php

« previous php.notes (#136517) next »