Thumbnails nur s/w, schlechte Quali

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Thumbnails nur s/w, schlechte Quali

    Hallo Forum-Gemeinde

    Ich programmiere gerade eine Liste um meine Games zu verwalten. Dabei soll ein Thumbnail der Covers gemacht werden auf die man klicken kann und das ganze dann in einem neuen Fenster in wahrer Grösse angezeigt wird.

    Für die Thumbnail-Erstellunge benutze ich folgendes (schon fertige) Script (thumb.php):

    PHP-Code:
    /*##############################################
         #          - Thumbnail-Script v1.3 -           #
         # Generating thumbnails 'on-the-fly' with PHP  #
         #                                              #
         #  (c) by Christian Lamine, FlashDreams OHG    #
         #          [url]http://www.flashdreams.de/[/url]          #
         #                                              #
         # 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 (=> "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 ($cachedir0777)
              : 
    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] == || $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$image0000$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); 
    Die Thumbnails kann ich dann wie folgt erstellen:

    PHP-Code:
    <img src=\"thumb.php?image=covers/test.jpg&x=100&resize=1\" class=\"coverdetails\"> 
    So weit so gut. Das ganze funktionier an und für sich auch, aber das Thumbnail wird nur in s/w und sehr schlechter Qualität angelegt (fast wie wenn ich es mit <img src="..." width="100">

    Beispiel (thumbnail):
    http://pascal007.homelinux.com/mygam...graw_cover.jpg

    Beispiel (original):
    http://pascal007.homelinux.com/mygam...graw_cover.jpg

    Kann es sein dass es an meinem internen Server liegt?

    PHP-Code:
    GD Support         enabled
    GD Version         bundled 
    (2.0.28 compatible)
    FreeType Support     enabled
    FreeType Linkage     with freetype
    FreeType Version     2.1.7
    GIF Read Support     enabled
    GIF Create Support     enabled
    JPG Support         enabled
    PNG Support         enabled
    WBMP Support         enabled
    XBM Support         enabled 
    Zuletzt geändert von wahsaga; 23.03.2007, 13:56.

  • #2
    Du verwendest imagecopyresized() anstatt imagecopyresampled() !

    Gruss

    tobi
    Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

    [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
    Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

    Kommentar


    • #3
      .... und imagecreate statt imagecreatetruecolor.....


      Gruß Sven

      Kommentar


      • #4
        Vielen, vielen Dank für eure Hilfe ! Jetzt funktioniert das Ganze einwandsfrei *riesig freu* .

        Hab jetzt noch eine Frage zu dem Script: es legt mir ja das Thmubnail mit dem selben Namen wie der original Datei an im Ordner Cache an. Ich habe jetzt für 2 Seiten 2 verschiedene Grössen (einmal 75px und einam 250px). Wenn ich jetzt das Thumb 250px im Cache-Ordner liegt und ich die Seite aufrufe wo ich sage dass mir ein 75px-Thumb generiert werden soll, überschreibt es mit natürlich mein 250er-Thumb im Ordner Cache... kann es so nicht zu Fehlanzeigen kommen, wenn zufälligerweise 2 User gleichzeit diese 75pxThumb-Seite und die 250pxThumb-Seite aufrufen?
        Zuletzt geändert von pascal007; 23.03.2007, 14:45.

        Kommentar


        • #5
          wird wohl eher selten passieren - markier doch lieber die Dateien als großes und kleines Thumb (thumb_70.jpg, thumb_250.jpg) - so sparst du auch Rechenaufwand
          Die Regeln | rtfm | register_globals | strings | SQL-Injections | [COLOR=silver][[/COLOR][COLOR=royalblue]–[/COLOR][COLOR=silver]][/COLOR]

          Kommentar

          Lädt...
          X