malenki / alpha-background
Requires
- php: >=5.3.0
- malenki/argile: *
This package is not auto-updated.
Last update: 2024-11-04 16:18:54 UTC
README
Alpha background are difficult with IE6, IE7 and IE8… So this is one of the solutions using PHP.
My little class allows you to generate small PNG image (1px×1px) to have background with alpha transparency, for IE7 and IE8.
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.
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.
How to install it?
Composer
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:
"require": {
"malenki/alpha-background": "*"
}
Then, you can instanciate it by new \Malenki\AlphaBackground()
.
Taking source code
For a quick use, download the source, take CLI or server version of script, chaned it to create image like you want.
For custom use
Examples are better than long blahblah so, I start by showing you how to display at the browser the image:
$rgba = new AlphaBackground(); $rgba->red(255); $rgba->green(150); $rgba->blue(42); $rgba->alpha(0.8); $rgba->display();
You can do it in one line too:
$rgba = new AlphaBackground(); $rgba->red(255)->green(150)->blue(42)->alpha(0.8)->display();
You can use hexadecimal string too :
$rgba = new AlphaBackground(); $rgba->hex('#ff962acc')->display();
The hexadecimal string can be without alpha:
$rgba = new AlphaBackground(); $rgba->hex('#ff962a')->alpha(0.8)->display();
You can use CSS color name too:
$rgba = new AlphaBackground(); $rgba->name('orange')->alpha(0.7)->display();
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:
$rgba = new AlphaBackground(); $rgba->name('orange')->alpha(0.7)->save('some_file.png');
For server
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.
background-image: url("/rgba-server.php?color=255,150,42,0.8"); background-image: url("/rgba-server.php?color=red,0.5");
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.
./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