Example #1
0
if (isset($_GET['height']) and trim($_GET['height']) != '') {
    $res_height = $_GET['height'];
} else {
    $res_height = $res_width / $width * $height;
}
$cache['prefix'] = '_slims_img_cache_' . $res_width . '_x_' . $res_height . '_';
$cache['file'] = $cache['folder'] . $cache['prefix'] . basename($imagefilename);
if (file_exists($cache['file'])) {
    $cache['exist'] = true;
    genContentType($imagefilename);
    readfile($cache['file']);
    exit;
} else {
    $cache['exist'] = false;
}
genContentType($imagefilename);
$target = imagecreatetruecolor($res_width, $res_height);
if (preg_match("/.jpg\$/i", $imagefilename)) {
    $source = imagecreatefromjpeg($imagefilename);
}
if (preg_match("/.gif\$/i", $imagefilename)) {
    $source = imagecreatefromgif($imagefilename);
}
if (preg_match("/.png\$/i", $imagefilename)) {
    $source = imagecreatefrompng($imagefilename);
}
imagecopyresampled($target, $source, 0, 0, $xoord, $yoord, $res_width, $res_height, $width, $height);
imagedestroy($source);
if ($cache['exist'] == false) {
    if (preg_match("/.jpg\$/i", $imagefilename)) {
        imagejpeg($target, null, 90);
    if (preg_match("/.gif\$/i", $_GET['filename'])) {
        header('Content-type: image/gif');
    }
    if (preg_match("/.png\$/i", $_GET['filename'])) {
        header('Content-type: image/png');
    }
}
if (file_exists($cache['file'])) {
    $cache['exist'] = true;
    genContentType();
    readfile($cache['file']);
    exit;
} else {
    $cache['exist'] = false;
}
genContentType();
// Rotate JPG pictures
if (preg_match("/.jpg\$|.jpeg\$/i", $_GET['filename'])) {
    if (function_exists('exif_read_data') && function_exists('imagerotate')) {
        $exif = exif_read_data($_GET['filename']);
        $ort = $exif['IFD0']['Orientation'];
        $degrees = 0;
        switch ($ort) {
            case 6:
                // 90 rotate right
                $degrees = 270;
                break;
            case 8:
                // 90 rotate left
                $degrees = 90;
                break;