You are here: Re: Transparent overlay watermark - on the fly - resolved? « PHP Programming Language « IT news, forums, messages
Re: Transparent overlay watermark - on the fly - resolved?

Posted by Chuck Anderson on 03/23/07 01:48

Geoff Berrow wrote:
> Message-ID: <5_SdnYs5293TaZ_bnZ2dnUVZ_v6tnZ2d@comcast.com> from Chuck
> Anderson contained the following:
>
>
>> Okay, I finally found the answer(s) I needed to make this work.
>>
>> First. For the watermark, you must use a 24 bit png (not 8 bit) - and
>> the best results, by far, are with alpha transparency. (A transparent
>> gif watermark works, but a transparent png produces much better quality.)
>>
>> Second - Do *not* use imagecopymerge (with a transparent png
>> watermark). It "destroys" the transparency in the png. I chose
>> imagecopyresampled because I want to re-size the watermark to fit the
>> image, and this produces better results than imagecopyresized.
>>
>
> Have you got some sample code?
>
>

Sure. I have not taken the size of the src image into account yet. This
example was a test of concept. I also want to rotate the watermark, but
here's how it is now. I started with the code from here:
<http://www.sitepoint.com/article/watermark-images-php> ... and reworked
some parts.

display_with_watermark.php
usage:
<img src="display_with_watermark.php?src=<?php echo
$path_to_source_image ?>">

<?php
$src = $_GET['src'];

// my watermark image is a 24 bit png with alpha channel transparency
$watermark = imagecreatefrompng('your_watermark_image.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);

$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($src);
$size = getimagesize($src);

// center in source image
$dest_x = ($size[0] - $watermark_width)/2;
$dest_y = $size[1]/2 - $watermark_height/2;

// place in top third of image
imagecopyresampled($image, $watermark, $dest_x,
$dest_y/2 - $watermark_height/2, 0, 0, $watermark_width,
$watermark_height, $watermark_width, $watermark_height);

// centerd and half sized
imagecopyresampled($image, $watermark,
$dest_x + $watermark_width/4, $dest_y + $watermark_height/4,
0, 0, $watermark_width/2, $watermark_height/2,
$watermark_width, $watermark_height);

// place in bottom third
imagecopyresampled($image, $watermark, $dest_x,
$dest_y + $dest_y/2 + $watermark_height/2, 0, 0,
$watermark_width, $watermark_height, $watermark_width,
$watermark_height);

header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename=' . $src);

imagejpeg($image);

imagedestroy($image);
imagedestroy($watermark);
?>

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация