Created
May 7, 2013 14:16
-
-
Save thedustin/5532878 to your computer and use it in GitHub Desktop.
Berechnet den Blendfarbanteil einer Farbe <color> bei Alpha-Wert <alpha> die auf der Farbe <blend> liegt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Berechnet den überblendeten Farbwert für eine einzige Farbe nach<br /> | |
* <pre>(alpha / 255) * argb.r() + (1 - alpha / 255) * blend.r()</pre><br /> | |
* Diese Funktion wird für jeden Farbanteil seperat aufgerufen. | |
* @param int $color Die Farbe die über eine andere Farbe gelegt werden soll | |
* @param float $alpha Der Alpha-Wert der Farbe <i>color</i> die über <i>blend</i> gelegt wird | |
* @param int $blend Der Farbwert der darunterliegenden Farbe (selben Types, also R-Angabe bei R,...).<br /> | |
* Standard ist 255 (Weiß) | |
* @return int Der neue Farbwert | |
* @link http://stackoverflow.com/questions/2780/converting-arbg-to-rgb-with-alpha-blending#answer-2789 | |
* @link https://en.wikipedia.org/wiki/Alpha_compositing | |
*/ | |
function calculateBlendColor($color, $alpha = 0.85, $blend = 255) { | |
return ceil(($alpha ) * $color + (1 - $alpha) * $blend); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment