Gazelle/image.php

103 lines
2.7 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-07-04 08:00:56 +00:00
// Functions and headers needed by the image proxy
2011-10-24 08:00:10 +00:00
error_reporting(E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR);
2011-03-28 14:21:28 +00:00
2013-08-22 08:00:54 +00:00
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
header("HTTP/1.1 304 Not Modified");
2011-03-28 14:21:28 +00:00
die();
}
2013-06-26 08:01:00 +00:00
header('Expires: '.date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); // 120 days
header('Last-Modified: '.date('D, d-M-Y H:i:s \U\T\C', time()));
2011-03-28 14:21:28 +00:00
2013-04-13 08:00:19 +00:00
if (!extension_loaded('gd')) {
error('nogd');
}
2011-03-28 14:21:28 +00:00
2013-07-04 08:00:56 +00:00
function img_error($Type) {
2013-04-13 08:00:19 +00:00
header('Content-type: image/gif');
die(file_get_contents(SERVER_ROOT.'/sections/image/'.$Type.'.gif'));
2011-03-28 14:21:28 +00:00
}
function invisible($Image) {
$Count = imagecolorstotal($Image);
2013-04-13 08:00:19 +00:00
if ($Count == 0) {
return false;
}
2011-03-28 14:21:28 +00:00
$TotalAlpha = 0;
2013-04-13 08:00:19 +00:00
for ($i = 0; $i < $Count; ++$i) {
2013-06-26 08:01:00 +00:00
$Color = imagecolorsforindex($Image, $i);
2011-03-28 14:21:28 +00:00
$TotalAlpha += $Color['alpha'];
}
2013-10-22 08:01:07 +00:00
return (($TotalAlpha / $Count) == 127) ? true : false;
2012-10-11 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
}
function verysmall($Image) {
return ((imagesx($Image) * imagesy($Image)) < 25) ? true : false;
}
function image_type($Data) {
2013-06-26 08:01:00 +00:00
if (!strncmp($Data, 'GIF', 3)) {
return 'gif';
}
2013-06-26 08:01:00 +00:00
if (!strncmp($Data, pack('H*', '89504E47'), 4)) {
return 'png';
}
2013-06-26 08:01:00 +00:00
if (!strncmp($Data, pack('H*', 'FFD8'), 2)) {
return 'jpeg';
}
2013-06-26 08:01:00 +00:00
if (!strncmp($Data, 'BM', 2)) {
return 'bmp';
}
2013-06-26 08:01:00 +00:00
if (!strncmp($Data, 'II', 2) || !strncmp($Data, 'MM', 2)) {
return 'tiff';
}
}
2011-03-28 14:21:28 +00:00
function image_height($Type, $Data) {
$Length = strlen($Data);
global $URL, $_GET;
2013-04-13 08:00:19 +00:00
switch ($Type) {
2011-03-28 14:21:28 +00:00
case 'jpeg':
// See http://www.obrador.com/essentialjpeg/headerinfo.htm
$i = 4;
$Data = (substr($Data, $i));
$Block = unpack('nLength', $Data);
$Data = substr($Data, $Block['Length']);
2013-04-13 08:00:19 +00:00
$i += $Block['Length'];
2011-03-28 14:21:28 +00:00
$Str []= "Started 4, + ".$Block['Length'];
2013-04-13 08:00:19 +00:00
while ($Data != '') { // iterate through the blocks until we find the start of frame marker (FFC0)
2011-03-28 14:21:28 +00:00
$Block = unpack('CBlock/CType/nLength', $Data); // Get info about the block
2013-06-26 08:01:00 +00:00
if ($Block['Block'] != '255') { // We should be at the start of a new block
break;
}
2013-04-13 08:00:19 +00:00
if ($Block['Type'] != '192') { // C0
$Data = substr($Data, $Block['Length'] + 2); // Next block
2013-06-26 08:01:00 +00:00
$Str []= "Started $i, + ".($Block['Length'] + 2);
2013-04-13 08:00:19 +00:00
$i += ($Block['Length'] + 2);
2011-03-28 14:21:28 +00:00
} else { // We're at the FFC0 block
$Data = substr($Data, 5); // Skip FF C0 Length(2) precision(1)
2013-04-13 08:00:19 +00:00
$i += 5;
2011-03-28 14:21:28 +00:00
$Height = unpack('nHeight', $Data);
return $Height['Height'];
}
}
break;
case 'gif':
$Data = substr($Data, 8);
$Height = unpack('vHeight', $Data);
return $Height['Height'];
case 'png':
$Data = substr($Data, 20);
$Height = unpack('NHeight', $Data);
return $Height['Height'];
default:
return 0;
}
}
2013-08-22 08:00:54 +00:00
define('SKIP_NO_CACHE_HEADERS', 1);
2013-07-04 08:00:56 +00:00
require('classes/script_start.php'); // script_start contains all we need and includes sections/image/index.php
2011-03-28 14:21:28 +00:00
?>