<?php
/* Autor: sroesler*/

function makeThumbnail($o_file, $t_ht, $t_wd)
{
    $image_info = getImageSize($o_file) ; // see EXIF for faster way

    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF)  { // not the same as IMAGETYPE
                $o_im = imageCreateFromGIF($o_file) ;
            } else {
                $ermsg = 'GIF images are not supported<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG)  {
                $o_im = imageCreateFromJPEG($o_file) ;
            } else {
                $ermsg = 'JPEG images are not supported<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG)  {
                $o_im = imageCreateFromPNG($o_file) ;
            } else {
                $ermsg = 'PNG images are not supported<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP)  {
                $o_im = imageCreateFromWBMP($o_file) ;
            } else {
                $ermsg = 'WBMP images are not supported<br />';
            }
            break;
        default:
            $ermsg = $image_info['mime'].' images are not supported<br />';
            break;
    }

    if (!isset($ermsg))
    {
        $o_wd = imagesx($o_im);
        $o_ht = imagesy($o_im);
        if (!$t_ht) $t_ht = round($o_ht * $t_wd / $o_wd) ;

        //kleiner Bilder nicht skalieren
        if ($o_wd<$t_wd) $t_wd=$o_wd;
        if ($o_ht<$t_ht) $t_ht=$o_ht;

        // thumbnail width = target * original width / original height
        $t_im = imageCreateTrueColor($t_wd,$t_ht);

        imagealphablending($t_im, false);
        $color = imagecolortransparent($t_im, imagecolorallocatealpha($t_im, 0, 0, 0, 127));
        imagefill($t_im, 0, 0, $color);
        imagesavealpha($t_im, true);
        imagecopyresampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd,$o_ht);

        ImagePng($t_im);
        imageDestroy($o_im);
        imageDestroy($t_im);
    }
    return isset($ermsg)?$ermsg:NULL;
}

header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header("Content-type: image/png");
$url='http://'.$_SERVER['HTTP_HOST'].$_GET['url'];

makeThumbnail($url, (isset($_GET['hoehe'])?$_GET['hoehe']:185), (isset($_GET['breite'])?$_GET['breite']:728));
?>