File "image.php"

Full Path: /home/analogde/www/files03/other/ImageEditor/image.php
File size: 5.9 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2003-2004 Tobias Bender (tobias@phpXplorer.org)
*  All rights reserved
*
*  This script is part of the phpXplorer project. The phpXplorer project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt distributed with these scripts.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

if(function_exists("gd_info")){
	$gdInfo = gd_info();
	$bVersion2 = strpos($gdInfo['GD Version'], "2.") !== false ? true : false;
}else{
	$bVersion2 = false;
}

require(dirname(__FILE__) . "/config.php");

if(isset($HTTP_GET_VARS['imageLib'])){
	$imageLib = $HTTP_GET_VARS['imageLib'];
}else{
	$imageLib = $IE_image_library;
}

$path = realpath(urldecode($HTTP_GET_VARS['path']));

$maxLen = isset($HTTP_GET_VARS["maxLen"]) ? $HTTP_GET_VARS["maxLen"] : 0;

$path = str_replace("http://" . $HTTP_SERVER_VARS["HTTP_HOST"], realpath($HTTP_SERVER_VARS["DOCUMENT_ROOT"]), $path);

$fi = pathinfo($path);

$extension = $fi["extension"];
$folder = $fi["dirname"];

$sUrl = str_replace(chr(92), '/', str_replace(realpath($HTTP_SERVER_VARS["DOCUMENT_ROOT"]), $HTTP_SERVER_VARS["HTTP_HOST"], $folder));

$sPart = "/$IE_thumbs_dir/thumb" . $maxLen . "_" . $fi["basename"];

$thumbFilePath = $folder . $sPart;
$thumbFileURL = "http://" . $sUrl . $sPart;

if(file_exists($thumbFilePath)){# AND filemtime($path) < filemtime($thumbFilePath)   / wegen stratos gd1 noch nicht einbauen, da richtige daten beim hochladen verloren gehen
  header("Location: $thumbFileURL");
	exit;
}else{
  if($maxLen == 0){
	  header("Location: http://" . $sUrl . "/" . $fi["basename"]);
		exit;
	}else{
		if($IE_cache_thumbs or $imageLib == 0)
		  if(!is_dir($folder . "/$IE_thumbs_dir"))
			  if(!@mkdir($folder . "/$IE_thumbs_dir", 0755)){
					$imError = ImageCreate(100,100);
					$background_color = ImageColorAllocate ($imError, 255, 255, 255);
					ImageString($imError, 1, 5, 5, "Cannot create", ImageColorAllocate ($imError, 0, 53, 102));
					ImageString($imError, 1, 5, 20, "_thumbs folder.", ImageColorAllocate ($imError, 0, 53, 102));
					ImageString($imError, 1, 5, 35, "Please change", ImageColorAllocate ($imError, 0, 53, 102));
					ImageString($imError, 1, 5, 50, "folder", ImageColorAllocate ($imError, 0, 53, 102));
					ImageString($imError, 1, 5, 65, "permissions.", ImageColorAllocate ($imError, 0, 53, 102));
					ImagePNG($imError);
					exit;
				}
				
		if($imageLib == 0){
		  copy($path, $thumbFilePath);
			system('mogrify -resize ' . $maxLen . 'x' . $maxLen . ' -quality 80 "' . $thumbFilePath . '"');
			header("Location: $thumbFileURL");
			exit;
		}else{
		  $size = GetImageSize($path);
			$x = $size[0];
			$y = $size[1];
			
			switch(strtoupper($extension)){
			case 'JPG':
			  header("Content-type:image/jpeg");
				$image = imagecreatefromjpeg($path);
			break;
			case 'JPEG':
			  header("Content-type:image/jpeg");
				$image = imagecreatefromjpeg($path);
			break;
			case 'GIF':
			  header("Content-type:image/gif");
  			$image = imagecreatefromgif($path);
			break;
			case 'PNG':
			  header("Content-type:image/png");
				$image = imagecreatefrompng($path);
			break;
			}
  	  if($x > $y){#quer
  		  if($x >= $maxLen){
  			  $newY = $y * ($maxLen / $x);

					if($bVersion2){
						$imageOut = ImageCreateTrueColor($maxLen, $newY);
					}else{
						$imageOut = ImageCreate($maxLen, $newY);
					}
					
					if($bVersion2){
						imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $maxLen, $newY, $x, $y);
					}else{
						imagecopyresized($imageOut, $image, 0, 0, 0, 0, $maxLen, $newY, $x, $y);
					}
  			}else{
  			  $newY = $y;

					if($bVersion2){
						$imageOut = ImageCreateTrueColor($x, $newY);
					}else{
						$imageOut = ImageCreate($x, $newY);
					}

					if($bVersion2){
						imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $x, $newY, $x, $y);
					}else{
						imagecopyresized($imageOut, $image, 0, 0, 0, 0, $x, $newY, $x, $y);
					}
  			}
  		}else{#hoch
  		  if($y >= $maxLen){
  				$newX = $x * ($maxLen / $y) - 0.4;

					if($bVersion2){
						$imageOut = ImageCreateTrueColor($newX, $maxLen);
					}else{
						$imageOut = ImageCreate($newX, $maxLen);
					}

					if($bVersion2){
						imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $newX, $maxLen, $x, $y);
					}else{
						imagecopyresized($imageOut, $image, 0, 0, 0, 0, $newX, $maxLen, $x, $y);
					}
  			}else{
					$newX = $x;

					if($bVersion2){
						$imageOut = ImageCreateTrueColor($newX, $y);
					}else{
						$imageOut = ImageCreate($newX, $y);
					}
					
					if($bVersion2){
						imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $newX, $y, $x, $y);
					}else{
						imagecopyresized($imageOut, $image, 0, 0, 0, 0, $newX, $y, $x, $y);
					}
  			}
  		}
			if($IE_cache_thumbs){
				switch(strtoupper($extension)){
					case 'JPG' : imageJPEG($imageOut, $thumbFilePath); break;
					case 'JPEG' : imageJPEG($imageOut, $thumbFilePath); break;
					case 'GIF' : imageGIF($imageOut, $thumbFilePath); break;
					case 'PNG' : imagePNG($imageOut, $thumbFilePath); break;
	  		}
				header("Location: $thumbFileURL");
			}else{
				switch(strtoupper($extension)){
					case 'JPG' : imageJPEG($imageOut); break;
					case 'JPEG' : imageJPEG($imageOut); break;
					case 'GIF' : imageGIF($imageOut); break;
					case 'PNG' : imagePNG($imageOut); break;
	  		}
			}
  	}
  }
}
?>