Wallogit.com
2017 © Pedro Peláez
A little class for generating 1×1 pixel gifs.
Pxgif is a little class for generating 1 pixel gifs., (*1)
You probably don't need to generate 1 pixel gifs unless you are a little OCD about returning the correct content type from your rest api. And the purpose of this class is just that. Here are some use-cases:, (*2)
You are making a google-anlytics style tracker that adds an image to the page to track a pageview.
You can write out a 1 pixel transparent gif with echo Pxgif::gifStr(0, 0, 0, true)., (*3)
Say you are writing a php script to manipulate an image in some way (ex. facebook passes most images through a safe_image.php script).
If that script fails you should still write a valid image since the browser expecting one.
You can write out a 1 pixel gif to indicate the http error code echo Pxgif::httpStr($code)., (*4)
To use Pxgif you only need to include one file: Pxgif.php. Then all you need to do is call any of the static methods on the Pxgif class., (*5)
The following example will output a 1 pixel transparent gif., (*6)
// Require the class.
require 'Pixgif.php';
// Do something interesting, like track a page view.
// ...
// Set the appropriate response headers.
header("Content-type: image/gif");
header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
header("Cache-Control: no-cache");
header("Cache-Control: must-revalidate");
// Dump the gif.
Pxgif::gifStr();
When you call Pxgif::httpStr() you will get a string that represents an a 1 pixel gif for an http status code. The gif is color-coded to represent the success or severity of the error., (*7)
The gifs are color coded according to their error types., (*8)
If you are really observant you'll be able to figure out the response code just by looking at the color of the generated gif (hint, read the hex code) (hint, hint: look at the source code)., (*9)