Dennis: Thumbs ohne Cache

Beitrag lesen

Hallo,

habe ein wirklich klasse thumb-PHP-Script gefunden, würde das nur gerne ohne die cache-Funktion benutze.
Kann mir jemand sagen, wie ich den folgenden Code umbauen muss, damit das Bild ohne zu cachen direkt ausgegeben wird - weiß zwar, dass das nicht so gut ist, soll aber lokal laufen ...

<?php

/*##############################################
     #          - Thumbnail-Script v1.3 -           #
     # Generating thumbnails 'on-the-fly' with PHP  #
     #                                              #
     #  (c) by Christian Lamine, FlashDreams OHG    #
     #          http://www.flashdreams.de/          #
     #                                              #
     # This script may be freely used, distributed  #
     # and modified without any charge as long as   #
     # this copyright information is included.      #
     #                                              #
     # Any commercial selling of this script is     #
     # prohibited.                                  #
     #                                              #
     # The author is not responsible for possible   #
     # damage which may result from the application #
     # of this script, neither direct nor indirect. #
     # Use at your own risk!                        #
     ##############################################*/

error_reporting(0);

$types = array (1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");

define ('cache', 'cache/');

$cachedir = substr($HTTP_GET_VARS['image'],0,strrpos($HTTP_GET_VARS['image'],'/') + 1).cache;
     !is_dir ($cachedir)
          ? mkdir ($cachedir, 0777)
          : system ("chmod 0777 ".$cachedir);

(!isset ($x) || ereg ('[1]{1,}$', $x, $regs)) &&
     (!isset ($y) || ereg ('[2]{1,}$', $y, $regs)) &&
     (isset ($x) || isset ($y))
          ? true
          : DIE ('Fehlende(r) oder ungültige(r) Größenparameter!');

!isset ($resize) || !ereg ('[3]$', $resize, $regs)
          ? $resize = 0
          : $resize;

!isset ($aspectratio) || !ereg ('[4]$', $aspectratio, $regs)
          ? isset ($x) && isset ($y)
                 ? $aspectratio = 1
                 : $aspectratio = 0
          : $aspectratio;

!isset ($image)
          ? DIE ('Es wurde kein Bild angegeben!')
          : !file_exists($image)
               ? DIE ('Die angegebene Datei konnte nicht auf dem Server gefunden werden!')
               : false;

$imagedata = getimagesize($image);

!$imagedata[2] || $imagedata[2] == 4 || $imagedata[2] == 5
          ? DIE ('Bei der angegebenen Datei handelt es sich nicht um ein Bild!')
          : false;

eval ('
     if (!(imagetypes() & IMG_'.strtoupper($types[$imagedata[2]]).')) {
          DIE ("Das ".strtoupper($types[$imagedata[2]])."-Format wird nicht unterstützt!");
     }
     ');

!isset ($x)
          ? $x = floor ($y * $imagedata[0] / $imagedata[1])
          : $x;

!isset ($y)
          ? $y = floor ($x * $imagedata[1] / $imagedata[0])
          : $y;

if ($aspectratio && isset ($HTTP_GET_VARS['x']) && isset ($HTTP_GET_VARS['y'])) {
          if ($imagedata[0] > $imagedata[1]) {
               $y = floor ($x * $imagedata[1] / $imagedata[0]);
          } else if ($imagedata[1] > $imagedata[0]) {
               $x = floor ($y * $imagedata[0] / $imagedata[1]);
          }
     }

$thumbfile = substr ($HTTP_GET_VARS['image'], strrpos ($HTTP_GET_VARS['image'], '/') + 1);
     if (file_exists ($cachedir.$thumbfile)) {
          $thumbdata = getimagesize ($cachedir.$thumbfile);
          $thumbdata[0] == $x && $thumbdata[1] == $y
               ? $iscached = true
               : $iscached = false;
     } else {
          $iscached = false;
     }

if (!$iscached) {
          ($imagedata[0] > $x || $imagedata[1] > $y) ||
          (($imagedata[0] < $x || $imagedata[1] < $y) && $resize)
               ? $makethumb = true
               : $makethumb = false;
     } else {
          $makethumb = false;
     }

Header ("Content-Type: image/".$types[$imagedata[2]]);

if ($makethumb) {
          $image = call_user_func("imagecreatefrom".$types[$imagedata[2]], $image);
          $thumb = imagecreate ($x, $y);
          imagecopyresized ($thumb, $image, 0, 0, 0, 0, $x, $y, $imagedata[0], $imagedata[1]);
          call_user_func("image".$types[$imagedata[2]], $thumb, $cachedir.$thumbfile);
          imagedestroy ($image);
          imagedestroy ($thumb);
          $image = $cachedir.$thumbfile;
     } else {
          $iscached
               ? $image = $cachedir.$thumbfile
               : $image = $HTTP_GET_VARS['image'];
     }
     $image = fopen ($image, "rb");
     fpassthru ($image);
     fclose ($image);

?>

Ich danke recht herzlich,
Dennis


  1. 0-9 ↩︎

  2. 0-9 ↩︎

  3. 0|1 ↩︎

  4. 0|1 ↩︎