<?php
function mkthumb($path)
{
$pathinfo = pathinfo($path);
if ( strtolower($pathinfo['extension']) == 'gif' )
{
$icfunc = 'imagecreatefromgif';
}
elseif ( strtolower($pathinfo['extension']) == 'png' )
{
$icfunc = 'imagecreatefrompng';
}
else
{
$icfunc = 'imagecreatefromjpeg';
}
unset($pathinfo);
$is = $icfunc($path);
if ( !$is )
{
$str = ($path == 'no_photo') ? 'Album has no photo' : 'Error loading image';
return display_error($str);
}
else
{
$sw = imagesx($is);
$sh = imagesy($is);
if ($sw > 133)
{
$factor = $sw/133;
$dw = floor($sw/$factor);
$dh = floor($sh/$factor);
}
else
{
$dw = $sw;
$dh = $sh;
}
if ($dh > 71)
{
$factor = $dh/71;
$dw = floor($dw/$factor);
$dh = floor($dh/$factor);
}
$id = imagecreatetruecolor($dw, $dh);
imagecopyresampled($id, $is, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
return $id;
}
}
function display_error($str)
{
$ir = imagecreate(133, 71);
$bgc = imagecolorallocate($ir, 255, 255, 255);
$tc = imagecolorallocate($ir, 0, 0, 0);
imagefilledrectangle($ir, 0, 0, 133, 71, $bgc);
imagestring($ir, 2, 10, 30, $str, $tc);
return $ir;
}
$ir = mkthumb($_GET['path']);
$ct = get_mime($_GET['path']);
if ( ($ct == 'gif') && function_exists('imagegif') )
{
$df = 'imagegif';
}
elseif ( ($ct == 'png') && function_exists('imagepng') )
{
$df = 'imagepng';
}
elseif ( function_exists('imagejpeg') )
{
$df = 'imagejpeg';
}
else
{
die('No image support!');
}
common_header();
header('Content-Disposition: inline');
header('Content-Type: '.$ct);
$df($ir);
?>