Admin@mbox3.magellan-net.de
alina@yourmx.de
bm@schweinischer-bote.de
boris@cosmeta.de
boss@dan2n.de
btiggemann@mbox3.magellan-net.de
catcher009@blacknbeauty.de
Christopher_Zantopp@web.de
dok123@discardmail.com
dominik.keilbach@rocketmail.com
dominik2712@web.de
einkauf@dan2n.de
elke@kunesch.eu
erik_burgbacher_bi17l4lo@send.electronicmailfor.me.uk
feedme@die-bauer.de
feedme@dog-net.org
feedme@drakensang.de-web.cc
feedme@kraffner.de
feedme@schlaegel.it
feedme@sql-kunesch.de
feedme@wipeout6.de
fetcher@open-host.de
frank@spiracyworld.co.uk
getspam@schlaegel-online.de
harun-ali@web.de
iCollectGarbage@gmx.de
ifyoudone@r0ckt.de
ifyyou@r0ckt.de
info@die-bauer.de
info@mbox3.magellan-net.de
info@r0ckt.de
info@rbcms.de
john.deer@spamreducer.eu
john@cannedmeat.elementfx.com
k.tramm@xspin.de
Karl-Heinz.Becher@gmx.de
Kevin.Becaud@bio-muesli.info
kickers88@live.de
knuddels119k@yahoo.de
loremiosumsitdoloramet@yahoo.de
loremiosumsitdoloramet@yahoo.de
lotharwalter@ymail.com
luna@r0ckt.de
matz0302oyqp@domut.de
mgoessel@gmx.net
michael.k@drakensang.de-web.cc
michael.k@drakensang.de-web.cc
michael.k@sql-kunesch.de
michaknopf@googlemail.com
mk@r0ckt.de
msneijder@mbox3.magellan-net.de
nasti_mkorsa@sql-kunesch.de
newcyborg@gmx.net
schlucks@gmx.net
schwarz@die-bauer.de
service@mbox3.magellan-net.de
sp4mf4ng@j-schmitz.net
spam@teh1.de
spamcatcher@spamtrap.dtdns.net
spamela@spamschlucker.org
spamhog.ihatespam@gmail.com
spamlearn@schlarb-it.de
spamlearn@schlarb-it.de
spamtarget@junge-piraten.de
spamtrap@r0ckt.de
spamtrap@sprachdidaktik.org
spoof@dog-net.org
stephan@spamschlucker.org
support@mbox3.magellan-net.de
thanks@marvin-webservice.net
trap.mitschutz@sprachdidaktik.org
trap@sprachdidakt.de
trap@sprachdidaktik.org
trep@marvin-webservice.net
unwanted@shadowpage.de
vertrieb@dan2n.de
wb@munzinger.de
willmehr@drakensang.de-web.cc
willmehr@drakensang.de-web.cc
willmehr@wipeout6.de
wir@dragoncrew.de
xkbzy@grossermist.de
a Image

The GD-Lib is a very powerfull extension for PHP.

but in one case, it really fails.

Imagine, you want to merge an image with ৺alpha channels with another one.
No magic: u can use the ৺imagecopy() function. It will look like this:

Another Pic
imagecopy with an alpha channel watermark


Imagine, you want to merge an image without ৺alpha channels with another one,
AND add opacity.
No magic: u can use the imagecopymerge() function. (The ৺banner has white background)

Another Pic
imagecopymerge using alpha of 50


But now, imagine, you want to merge an image with ৺alpha channels with another one,
AND add opacity.

In this case, the GD-Lib fails:

Another Pic
imagecopymerge using alpha of 50 AND and watermark with alpha channels


Background:
Each pixel on an image is defined by 4 values: red, green, blue and ৺alpha.
If you use the ৺imagecopy function, the ৺alpha value will be preserved, which means:
what IS transparent will be transparent after merging.

If you use the imagecopymerge function you can set the new ৺alpha channel, BUT:
If you set up an ৺alpha channel of 100 (nearly transparent) EACH pixel will get this ৺alpha value.
This means, that if there are pixel with a value of 127 (totally transparent), they will be visible after merging - like in the third example above.

Solution:
i wrote an function called "imagecopymergealpha" which is able to solve this problem:

Another Pic
imagecopymergealpha


As u can see, transparent pixel are "staying" transparent, and opaque pixels are getting "more" transparent.

And this is, where the magic happens:

  1.  
  2. function imagecopymergealpha(&$dest_img, &$src_img, $dest_x, $dest_y, $src_x, $src_y, $src_width, $src_height, $alpha){
  3.   $new_src = imagecreatetruecolor($src_width, $src_height);
  4.   imagefill($new_src,0,0, imagecolorallocatealpha($new_src,255,255,255,127));
  5.   for ($x=0; $x < $src_width; $x++){
  6.     for ($y=0; $y < $src_height; $y++){
  7.       $color = imagecolorsforindex($src_img,imagecolorat($src_img,$x,$y));
  8.       $new_alpha = $color["alpha"];
  9.       $new_alpha += $alpha;
  10.       if ($new_alpha > 127) $new_alpha = 127;
  11.       $newColor = imagecolorallocatealpha($src_img,$color["red"],$color["green"],$color["blue"], $new_alpha);
  12.       imagesetpixel($new_src,$x,$y,$newColor);
  13.     }
  14.   }
  15.   imagecopy($dest_img,$new_src,$dest_x,$dest_y,$src_x,$src_y,$src_width,$src_height);
  16.   imagedestroy($new_src);
  17. }
  18.  


the last parameter - which is the "total" ৺alpha channel can get values from 0 - 127, where 0 means opaque and 127 totally invisible

Update 2009-11-09: Added imagedestroy command to free memory.

Related Tags:

Stay tuned:

r a t y y

Top 25 Tag-Cloud (last 14 days):

Trackbacks on this post:

Comments on this post:

Not yet a comment...

Leave a Comment:

Captcha-Code:        reload
Name:
Captcha:
Comment:

Donate!

Like my stuff? Feel free to donate!
 
Modellbau Forum pspad Browser-Statistiken WhatPulse logo dog-net.org Valid XHTML 1.0 Transitional CSS ist valide!

DevelopmentPHP | 2009-08-26 16:35:21

LeadImage

rand or mt_rand?

Random numbers are often useful - but those are these pseudo random numbers really random?

read more...

DevelopmentPHP | 2009-08-19 23:27:25

LeadImage

Easy Permission Management System

Heres a sample of a easy ৺permission management system.

read more...

DevelopmentPHP | 2009-07-12 02:30:50

LeadImage

Captcha With Real Tff And Background

Here you can find a ৺captcha code, that uses real tiff fonts as well as random background images. This is a improved version of my older ৺captcha, which completly was made by colors, default fonts and shapes.

read more...

DevelopmentPHP | 2009-07-09 03:22:13

LeadImage

MySQL Connection Class

A Long time ago, i wrote a Class, that makes ৺SQL-Querys easier. Nearly everything is done without caring about all the PHP ৺SQL-Functions.

read more...

DevelopmentPHP | 2009-07-09 03:22:05

LeadImage

MakeNiceSize

This is the php function, i use to create user friendly file size strings. Sizes like 215742435 byte or 0,00000000023 GB are NOT user friendly.

read more...

DevelopmentPHP | 2009-07-09 03:21:44

LeadImage

Dynamic Style Sheets

Copyright © 2008 - 2010 | by dog.net Development | Imprint | Load in 1.94015