thumbnailerzeugeung macht miserable qualität



  • hi leute
    http://www.serez.de/index.php?action=show&katid=4&l=0
    dort erstelle cih kleine thumbnails, aber schaut euch mal die qualität an - die ist doch net mehr schön oder?

    den code dazu habe ich geklaut - allerdings finde ich dirt nix in sachen qualität

    <?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[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 finde da nix zu, auch net im web - wie die qualitäöt gesteigert werden kann 😞



  • unten das image_create() durch das neuere imagecreatetruecolor ersetzen!
    Dann das imagecopyresized() durch das neuere imagecopyresampled
    ersetzen.

    Dann haste nicht mehr nur 256 Farben und imagecopyresampled() benutzt im gegensatz zu imagecopyresized() auch Interpolation 😉



  • super.....

    danke danke danke danke danke!
    top!

    bin halt noch net so der php funktionen kenner 😉



  • http://www.serez.de/show_1.php?katid=4&l=0

    hmm

    die qualität ist immer noch so doof 😞

    code

    <?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[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 = imagecreatetruecolor ("100", "145"); 
              imagecopyresampled ($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); 
    
    ?>
    

    habe es halt da unten an den stellen ersetzt 😞

    haste vllt noch nen tipp?



  • doch doch doch.
    hatte gerade mal den cache gelöscht.
    top

    thx


Anmelden zum Antworten