Location: PHPKode > scripts > ChiliGallery > ChiliGallery/thumb.php
<?PHP
/*
	--------------------------------------------------------
	ChiliGallery thumb.php v2.5
	based on the Gallery Script of pawlita.de
	--------------------------------------------------------
	The script is protected by copyright law. All rights and
	copyrights are held by the author:
	Adam Pawlita, http://www.chiliscripts.com
	This script may be freely used and redistributed so long
	the stated copyright notices in all parts of the script before-
	hands remain. For correct operation, or damage caused by
	the operation of this script is made only if the author has no
	Warranty. Commissioning is carried out in each case
	at their own risk of the operator.
	-------------------------------------------------------
*/

// Variables read and if no size given then use standard size
if ($_GET['w'] == "") {$w="160";} else {$w=$_GET['w'];}
if ($_GET['h'] == "") {$h="160";} else {$h=$_GET['h'];}
if ($_GET['thumb'] <> "") {$thumb=$_GET['thumb'];}
if ($_GET['art'] == "1") {$art="1";} else {$art=0;}

if ($thumb)
{
 // read out Image data
 $Bilddaten = getimagesize($thumb);
 $Format   = $Bilddaten[2];
 $OriginalBreite = $Bilddaten[0];
 $OriginalHoehe = $Bilddaten[1];
 // JPEG File ?
 if ($Format==2) 
 {
 // Create images
 $Originalgrafik = ImageCreateFromJPEG($thumb);

 if ($art=="0")
 {
 // calculate ratios
 if (($OriginalBreite/$w) > ($OriginalHoehe/$h)){
        //$ThumbnailBreite = $w; 
        $h = floor($OriginalHoehe * $w / $OriginalBreite); 
    } 
    else { 
        //$ThumbnailHoehe = $h; 
        $w = floor($OriginalBreite * $h / $OriginalHoehe); 
    } 

 // Create Thumbnail
 $Thumbnailgrafik = ImageCreateTrueColor($w, $h);
 ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $w, $h,   $OriginalBreite, $OriginalHoehe);
 }
 else
 {
  // Calculate ratios and find the center
 if (($OriginalBreite/$w) < ($OriginalHoehe/$h)){
	$AusschnittBreite=$OriginalBreite; 
	$AusschnittHoehe=($h*($OriginalBreite/$w));
	$OriginalPosX=0;
	$OriginalPosY=($OriginalHoehe-$AusschnittHoehe)/2;	}
 else{
	$AusschnittHoehe=$OriginalHoehe; 
	$AusschnittBreite=($w*($OriginalHoehe/$h));
	$OriginalPosX=($OriginalBreite-$AusschnittBreite)/2;
	$OriginalPosY=0;}

 // Create Thumbnail
 $Thumbnailgrafik = ImageCreateTrueColor($w, $h);
 ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, $OriginalPosX, $OriginalPosY, $w, $h, $AusschnittBreite, $AusschnittHoehe);
 }
 
 // Thumbnail output
 $ext = array_pop(explode('.', $thumb)); 
 $thumbname = basename($thumb,".".$ext); 
 header("Content-type: image/jpeg");
 header("Content-Disposition: attachment; filename=".$thumbname."_".$w."x".$h."");
 imagejpeg($Thumbnailgrafik,null,100);
 }
}

?>
Return current item: ChiliGallery