<?php
$path="images/products/";
switch ($_GET["sz"]) {
        case "sm":
                $opts="-scale 40x40";
                break;
        case "si":
                $opts="-resize 60x60";
                break;
        case "th":
                $opts="-resize 80x80";
                break;
        case "gd":
                $opts="-resize 100x100";
                break;
        case "md":
                $opts="-resize 250x250";
                break;
        case "vd":
                $opts="-scale x200";
                break;
        case "id":
                $opts="-resize 300x300";
                break;
        case "lg":
                $opts="-resize 400x300";
                break;
        case "fl":
                $opts="-resize '800x600>'";
                break;
        case "lo":
                $opts="-resize '135x50>'";
                break;
        case "cd":
                $opts="-resize '145x95'";
                break;
        case "ci":
                $opts="-resize '130x130'";
                break;
        default:
                $opts="-resize '800x600>'";
}
// Build path to picture while stripping out bad characters
$photo=$path.preg_replace('/[^a-zA-Z0-9\/_.+-]/','',$_GET["image"]);
// Determine image type and set appropriate options
$ext=strtolower(strrchr($photo, '.'));
switch ($ext) {
        case ".png":
                $cvt="PNG";
                $type="image/png";
                break;
        case ".gif":
                $cvt="GIF";
                $type="image/gif";
                break;
        default:
                $cvt="JPG";
                $type="image/jpeg";
}
// Replace with empty image if file not found
if ( !file_exists($photo) || $photo==$path ) { $photo=$path."noimage.jpg"; }
// Build conversion command string
$cmd = "/usr/bin/convert $opts '$photo' ".$cvt.":-";
// Output converted image
header("Content-type: ".$type);
passthru($cmd, $retval);
?>

