This is a discussion on png transparency operations within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I found the following code to add a watermark to an image. It takes a png source as a watermark. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I found the following code to add a watermark to an image. It takes a
png source as a watermark. Problem is, it doesn't appear to handle transparancy. My png has a single color background that I want to set as transparent, which I've done in paintshop, but when I run it through the code below, the output image displays the entire png as a rectangular block with no transparency. Are there any transparency operations for png possible with php? <?php header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($_GET['src']); $size = getimagesize($_GET['src']); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> |
|
|||
|
test@gesg.com (Sir Loin of Beef) wrote in
news:4209613d.4694221@news.starhub.net.sg: > I found the following code to add a watermark to an image. It takes a > png source as a watermark. And you are using imagejpeg(), so it doesn't output a PNG image. > Are there any transparency operations for png possible with php? http://www.php.net/manual/en/functio...hablending.php -- Dave Patton Canadian Coordinator, Degree Confluence Project http://www.confluence.org/ My website: http://members.shaw.ca/davepatton/ |
|
|||
|
Yes, that's right.
I have 2 source files - a picture jpg, and a watermark png. The output is a jpg. Can I still maintain the transparency of the png watermark in the output jpg? Dave Patton <spam@trap.invalid> wrote: >test@gesg.com (Sir Loin of Beef) wrote in >news:4209613d.4694221@news.starhub.net.sg: > >> I found the following code to add a watermark to an image. It takes a >> png source as a watermark. > >And you are using imagejpeg(), so it doesn't output a PNG image. > >> Are there any transparency operations for png possible with php? > >http://www.php.net/manual/en/functio...hablending.php > >-- >Dave Patton >Canadian Coordinator, Degree Confluence Project >http://www.confluence.org/ >My website: http://members.shaw.ca/davepatton/ |
|
|||
|
On Wed, 09 Feb 2005 01:04:29 GMT, test@gesg.com (Sir Loin of Beef)
wrote: >I found the following code to add a watermark to an image. It takes a >png source as a watermark. >Problem is, it doesn't appear to handle transparancy. My png has a >single color background that I want to set as transparent, which I've >done in paintshop, but when I run it through the code below, the >output image displays the entire png as a rectangular block with no >transparency. As viewed in what browser? Internet Explorer has difficulty displaying a transparent .PNG image correctly. > >Are there any transparency operations for png possible with php? > > ><?php > >header('content-type: image/jpeg'); > >$watermark = imagecreatefrompng('watermark.png'); >$watermark_width = imagesx($watermark); >$watermark_height = imagesy($watermark); >$image = imagecreatetruecolor($watermark_width, $watermark_height); >$image = imagecreatefromjpeg($_GET['src']); >$size = getimagesize($_GET['src']); >$dest_x = $size[0] - $watermark_width - 5; >$dest_y = $size[1] - $watermark_height - 5; > >imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, >$watermark_width, $watermark_height, 100); >imagejpeg($image); >imagedestroy($image); >imagedestroy($watermark); > >?> |
|
|||
|
On Wed, 09 Feb 2005 01:04:29 GMT, test@gesg.com (Sir Loin of Beef) wrote:
>I found the following code to add a watermark to an image. It takes a >png source as a watermark. >Problem is, it doesn't appear to handle transparancy. My png has a >single color background that I want to set as transparent, which I've >done in paintshop, but when I run it through the code below, the >output image displays the entire png as a rectangular block with no >transparency. > >Are there any transparency operations for png possible with php? > > ><?php > >header('content-type: image/jpeg'); > >$watermark = imagecreatefrompng('watermark.png'); >$watermark_width = imagesx($watermark); >$watermark_height = imagesy($watermark); >$image = imagecreatetruecolor($watermark_width, $watermark_height); >$image = imagecreatefromjpeg($_GET['src']); >$size = getimagesize($_GET['src']); >$dest_x = $size[0] - $watermark_width - 5; >$dest_y = $size[1] - $watermark_height - 5; > >imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, >$watermark_width, $watermark_height, 100); >imagejpeg($image); >imagedestroy($image); >imagedestroy($watermark); > >?> I've tried that exact code here, with a 48x48 256-colour palettised PNG of a star shape with the background set transparent using Paint Shop Pro 8, and it works exactly as expected - watermark appears in bottom right of JPEG selected, with the JPEG image showing through the transparent parts of the watermark. What version of PHP are you on? This was on PHP 5.0.3 which includes a fairly recent version of GD, the library that does image handling in PHP. (I think 4.3.10 has about the same version). -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |