Wallogit.com
2017 © Pedro Peláez
Alpha background are difficult with IE6, IE7 and IE8… So this is one of the solutions using PHP., (*1)
My little class allows you to generate small PNG image (1px×1px) to have background with alpha transparency, for IE7 and IE8., (*2)
To use it, many options are available for you:
- use the class to include it into your source code. I provide for you composer.json file to make this easy
- use a server script, I have written a little one for you
- use a CLI script, to generate images by other way., (*3)
If you have some scruples to use an image for IE, I provide some features into my class to generate good line of CSS hacked for this browser of stone's age, so, IE6 is in this family too., (*4)
For custom use, by using my class to do what you want, use composer to include it into your project. In your composer.json file, include this:, (*5)
"require": {
"malenki/alpha-background": "*"
}
Then, you can instanciate it by new \Malenki\AlphaBackground()., (*6)
For a quick use, download the source, take CLI or server version of script, chaned it to create image like you want., (*7)
Examples are better than long blahblah so, I start by showing you how to display at the browser the image:, (*8)
``` php $rgba = new AlphaBackground(); $rgba->red(255); $rgba->green(150); $rgba->blue(42); $rgba->alpha(0.8); $rgba->display();, (*9)
You can do it in one line too: ``` php $rgba = new AlphaBackground(); $rgba->red(255)->green(150)->blue(42)->alpha(0.8)->display();
You can use hexadecimal string too :, (*10)
``` php $rgba = new AlphaBackground(); $rgba->hex('#ff962acc')->display();, (*11)
The hexadecimal string can be without alpha: ``` php $rgba = new AlphaBackground(); $rgba->hex('#ff962a')->alpha(0.8)->display();
You can use CSS color name too: ``` php $rgba = new AlphaBackground(); $rgba->name('orange')->alpha(0.7)->display();, (*12)
If you want save the image, into all previous example, replace the last used method by `save()`, this method take one argument, the file's name: ``` php $rgba = new AlphaBackground(); $rgba->name('orange')->alpha(0.7)->save('some_file.png');
I have written a little script to put on a server to display background image. To use it, simply use the following lines into your CSS file., (*13)
``` css background-image: url("/rgba-server.php?color=255,150,42,0.8"); background-image: url("/rgba-server.php?color=red,0.5");, (*14)
The script is simple, but it works, you can changed it to deserve your own need. ## For CLI You can create background image by using a little CLI script I have written for you. Following lines show you how to use it. ``` bash ./rgba-cli -r 255 -g 150 -b 42 -a 0.8 -o image.png ./rgba-cli -n red -a 0.5 -o image.png ./rgba-cli --red 255 --green 150 --blue 42 --alpha 0.8 --output image.png ./rgba-cli --name red --alpha 0.5 --output image.png ./rgba-cli --hex ff962a --alpha 0.8 --output image.png ./rgba-cli --hex ff962acc --output image.png