xcabur
Goto Top

PHP und GD-Library Script

Thumbnail on the Fly

Hallo zusammen

Ok, entweder stimmt was mit meinem Webserver nicht oder mir steht etwas gewaltiges auf der Leitung. Hab hier ein Script um thumbnails on the fly zu erzeugen aber irgendiwe will dies nicht und ich weiss nicht wieso.

Also ich habe eine thumb.php mit folgendem inhalt:

<?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 ('^[0-9]{1,}$', $x, $regs)) &&  
     (!isset ($y) || ereg ('^[0-9]{1,}$', $y, $regs)) &&  
     (isset ($x) || isset ($y))
          ? true
          : DIE ('Fehlende(r) oder ungültige(r) Größenparameter!');  

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

     !isset ($aspectratio) || !ereg ('^[0|1]$', $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 / $imagedata[1])
          : $x;
 
     !isset ($y)
          ? $y = floor ($x * $imagedata[1] / $imagedata)
          : $y;
 
     if ($aspectratio && isset ($HTTP_GET_VARS['x']) && isset ($HTTP_GET_VARS['y'])) {  
          if ($imagedata > $imagedata[1]) {
               $y = floor ($x * $imagedata[1] / $imagedata);
          } else if ($imagedata[1] > $imagedata) {
               $x = floor ($y * $imagedata / $imagedata[1]);
          }
     }

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

     if (!$iscached) {
          ($imagedata > $x || $imagedata[1] > $y) ||
          (($imagedata < $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, $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);
 
?>

und dann eine test.html datei, welche ich auch aufrufe mit folgendem inhalt

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Unbenanntes Dokument</title>
</head>

<body>

<img src="thumb.php?image=auto.jpg&x=100">  

</body>
</html>


Ich verwende XAMPP 2.1 (muss ich das noch was aktivieren?)
die test.html, die thumb.php und auto.jpg liegen alle im selben verzeichnis. Jedoch bekomme ich einfach nur ein rotes kreuz auf der website, welches mir anzeigt, dass das Bild nicht verfügbar ist. Als bildadresse steht dann "http://pcxpvmw01/woa/thumb.php?image=auto.jpg&x=100"

Was ich sehe, ist das ein cache ordner erstellt wird, jedoch ohne inhalt!


Weiss jemand was ich falsch mache?

Content-Key: 67215

Url: https://administrator.de/contentid/67215

Printed on: April 20, 2024 at 01:04 o'clock