Login   Register  
PHP Classes
elePHPant
Icontem

File: Images.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tarcísio Xavier Gruppi  >  Image to PHP Standalone Output  >  Images.php  >  Download  
File: Images.php
Role: Sample output
Content type: text/plain
Description: A sample output. use: <img src="SampleImages.php?i=docGif"/>
Class: Image to PHP Standalone Output
Generate a class to serve a list of images
Author: By
Last change: New image code packer function
Date: 2009-08-05 11:57
Size: 4,963 bytes
 

Contents

Class file image Download
<?php
class Images {
	protected static $files = array(
		"bPng"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAIAAADqq+PiAAAAJElEQVR4nGNgoA1gZGBg+P//P4LPyAhlIYtC2Ew0MoFUczEBAGP2FP74xbjgAA{3}ElFTkSuQmCC"
		),
		"b1Png"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAB4AAAA3CAIAAACU8W0LAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAVElEQVR4nO3VQQsAEAxA4U3+/1+eg8taEQ5ive8meYlCBADwAw1jM9tOaIx05WQ/a0gHdTI3up/A37xf8ueBkE6R5nm6l+YNIU2a9KNpvoJ7aaTQAPL6D0xxmEMAA{4}ElFTkSuQmCC"
		),
		"mPng"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAIAAADqq+PiAAAAKUlEQVR4nGNgoB34//8/GpsJmYMsjSKEohYNIEQZGRmxiGJXS1gUOwAAQZMU+0jrszAA{4}SUVORK5CYII="
		),
		"m1Png"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAE0AAABTCAIAAABVtx0MAAAAVUlEQVR4nO3RMQ6AQAhFwcX73xkLG4vtxARxpqIieflrAQAA{3}wUWZu726O5y+uvM6RBe6RnVML9vyEms6IKPnzHnvO8pdOAA{12}BmOwFwQBT7YxIP8wAAAABJRU5ErkJggg=="
		),
		"wPng"=>array(
			"image/png",
			"iV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YLrqur4MMnbvonpjtxB7iB3kDvIHeQOcge5g9xB7iB35A5tORH5KOccTXeQO8gd5A5yB7kjd5A7yB3kDnIHuYPcQe4gd5A7yB25g9xB7iB3kDvIHeQOcge5g9xhyB2Rs5y/DnL4JqY7yB3kDnJH7iB36MRG5A1mbC/6g43pDnIHuYPckTvIHTopG16Y7iB3kDvIHeQOcge5g9xB7iB3kDtyB7mD3EHuIHeQO8gd5A5yB7mD3JE7yB3kDnIHuYPcQe4gd5A7yB3kjtxB7iB3kDvIHeQOcge5g9xB7iB35A5yB7mD3EHuIHeQO8gd5A5yB7mD3JE7yB3kDnIHuYPcQe4gd5A7yB3kjtxB7iB3kDvIHeQOcge5g9xB7iB35A5yB7mD3EHuIHeQO8gd5A5yB7kjd5A7yB3kDnIHuYPcQe4gd5A7yB25g9xB7iB3kDvIHeQOk+1MChpJR/XihQAAAABJRU5ErkJggg=="
		),
		"zPng"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAIAAADqq+PiAAAAKElEQVR4nGNgoA1gZGBg+P//P4oQIyO6KjQVRAgx4bOUKOOIcxkEAABHhhT2QyNy0wAAAABJRU5ErkJggg=="
		),
		"plusPng"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAA{3}CpleexAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gIKCBYxXpsCwwAAAB10RVh0Q29tbWVudABDcmVhdGVkIHdpdGggVGhlIEdJTVDvZCVuAAAALElEQVQ4y2NgGPyAEUPkP3YJJmJNHFVIZ4WMKPGGR81w9PVowh26CkcBdQAAaPwDNpBLHo8AA{3}SUVORK5CYII="
		),
		"plus1Png"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAA{3}CpleexAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gIKCBcHiDqmGwAAAB10RVh0Q29tbWVudABDcmVhdGVkIHdpdGggVGhlIEdJTVDvZCVuAAAAK0lEQVQ4y2NgGAWjYBSQAhjxyv5HKGAi1sShoJARt39RldHP6uEd4MMKAAAe/QMclhgzBgAAAABJRU5ErkJggg=="
		),
		"z1Png"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAAAcAAAANCAIAAADqq+PiAAAAIklEQVR4nGNgGHjAyMDA8P//fxQhRkYUJWjSlAgRYRscAABjshH3HCPO9QAAAABJRU5ErkJggg=="
		),
		"z11Png"=>array(
			"image/png",
			"iVBORw0KGgoAAAANSUhEUgAAABQAAAAlCAIAAADNzV5SAAAACXBIWXMAAAsTAAALEwEAmpwYAAAATklEQVR4nO2TOwoAMAjFYu9/ZzsU3PrD16FgJpdHsghFURSAxeXuFzMzoGnMCyJqCIOU+Vn2rFZjVmdvazVmUfZ5rcaszj6a5b8qNf6UDiDHEh0l+HApAA{3}ElFTkSuQmCC"
		),
	);

	public static function unpackImageCode($code) {
		$newCode = "";
		$end = 0;
		$foundCloseTag = false;
		$lastFound = 0;
		$x = 0;
		do {
			$start = $x = strpos($code,"{",$end);
			if ($start > $end) {
				$newCode .= substr($code,$lastFound,$start-$lastFound);
				$char = substr($code,$start-1,1);
				while (!$foundCloseTag) {
					if ($code[++$x] == "}") $foundCloseTag = true;
				}
				$mult = substr($code,++$start,$x-$start);
				$newCode .= str_repeat($char,$mult);
				$end = $lastFound = ++$x;
				$foundCloseTag = false;
			} else {
				$newCode .= substr($code,$end);
			}
		} while ($start);
		return $newCode;
	}
	public static function getInlineCode($name) {
		if (isset(self::$files[$name])) {
			return "data:".self::$files[$name][0].";base64,".self::unpackImageCode(self::$files[$name][1]);
		} else {
			return "";
		}
	}
	public function __get($name) {
		if (headers_sent()) die();
		if (isset(self::$files[$name])) {
			header("Content-Type: ".self::$files[$name][0]);
			echo base64_decode($this->unpackImageCode(self::$files[$name][1]));
			die();
		} else {
			die();
		}
	}
}
if (realpath($_SERVER['SCRIPT_FILENAME']) == realpath(__FILE__) && isset($_GET["i"])) {
	$image = new Images();
	$image->$_GET["i"];
}