<?php
require_once('sitebase.inc');
$cnum=$_REQUEST['cnum'];
edset();

if ($_REQUEST['size'] != 't')
    {$prec=getrec('pics', 'picsno', $_REQUEST['picsno']);
    if (!$prec) {tophdr(); edsqlerr(); }
    header('Content-type: '.image_type_to_mime_type($prec['type']));
    if ($_REQUEST['size'] == 'l' )
        {echo $prec['fullpic']; }
    else
        {echo $prec['pic']; }
    }
else {// Get from $_SESSION
    define(THUMB, 70);
    $pic=$_SESSION['pics'][$_REQUEST['picsno']];
    header('Content-type: '.image_type_to_mime_type($pic['img_t']));
    if ($pic['img_w'] <= THUMB && $pic['img_h'] <= THUMB)
        {echo $pic['img']; }
    else
        {// Thumbnail
        $img_w=$pic['img_w'];
        $img_h=$pic['img_h'];
        $img=imagecreatefromstring($pic['img']);
        if (!$img) {ederr('imagecreatefromstring'); }
        if ($img_w > $img_h) $scale=THUMB/$img_w;
        else $scale=THUMB/$img_h;
        $nimg_w=$img_w*$scale;
        $nimg_h=$img_h*$scale;
        $nimg=imagecreatetruecolor($nimg_w, $nimg_h);
        if (!imagecopyresized($nimg, $img, 0, 0, 0, 0,
                                $nimg_w, $nimg_h, $img_w, $img_h))
            {ederr('imagecopyresampled'); }
        imagedestroy($img);
        if ($pic['img_t']==IMAGETYPE_JPEG) imagejpeg($nimg);
        else if ($pic['img_t']==IMAGETYPE_PNG) imagepng($nimg);
        else if ($pic['img_t']==IMAGETYPE_GIF) imagegif($nimg);
        else imagewbmp($nimg);
        imagedestroy($nimg);
        }
    }
?>
