Pixler: a transparent PNG pixel generator

I made a weensy little script for the theme I recently made (which I still have not named or prepared for distribution) which will generate single pixel transparent pngs to use as tiled background images in css.

demonstration toy

<?php    
 
	$p = imagecreatetruecolor(1, 1);
	imagesavealpha($p, true);
	$o = (100 - (int) $_GET['o']) * 1.27;
	$c = imagecolorallocatealpha($p, (int) $_GET['r'], (int) $_GET['g'], (int) $_GET['b'], $o);
	imagefill($p, 0, 0, $c);
	header("Content-type: image/png");
	imagepng($p);
 
?>

usage / parameters:

r
how much red to include: r=[0-255]
g
how much green to include: g=[0-255]
b
how much blue to include: b=[0-255]
o
how opaque the pixel should be: o=[0(fully transparent)-100(fully opaque)]

so…

pixler.php?r=255&g=255&b=255&o=50
will make a white pixel that is 50% visible.
pixler.php?r=255&o=100
will make a red pixel that is fully visible.
pixler.php
calling the script with no parameters will create an invisible black pixel (…).

trackback

Tags: , , , , 10 responses »
  1. Jorge's gravatar

    awesome script! i’ve been looking for exactly this script!!!!! kudos!

  2. atom's gravatar

    @Jorge

    this is one i made more recently, which is a tad better, and does gradients too:

    http://github.com/re5et/trickyInc/blob/master/images/trickyImg.php

  3. DouG Molidor's gravatar

    Pretty frikkin cool. Works like a charm.
    Do you have examples for JPG and GIF too?

    Thanks.

  4. atom's gravatar

    @DouG Molidor

    i suspect that you are slightly confused. Neither JPG or GIF support alpha channel transparency.

  5. Jorge's gravatar

    @atom i’ll try that out, thanks!

  6. The Sheraz's gravatar

    Nice snippit! We are using it on our splash page for a new project coming up. Cheers!

  7. 女性人体艺术's gravatar

    博客写的很好,有很多值得学习的地方,给博主留个言,记得回访哦。

  8. 人体艺术图片's gravatar

    博主写的真的很好,在这里给你留个言了,我的网站比较前卫,博主不要介意啊,以后多多关照。

  9. Guy's gravatar

    Great code, thanks!

  10. 青岛卓众信息科技有限公司's gravatar

    青岛卓众(www.chinajoyzone.com)给博主拜年来了,新的一年,祝博主前途似锦。

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.