• 100% gecoded unerstelt von mir!!!!!!!!!!!!!!!!!!!!!!
    [hide]

    Spoiler anzeigen
    PHP
    function image_resize_dimensions($source_width,$source_height,$thumb_width,$thumb_height)  {     $source_ratio = $source_width / $source_height;    $thumb_ratio = $thumb_width / $thumb_height;    // Ratio is Taller    if ($thumb_ratio > $source_ratio)    {      $result_height = $thumb_height;      $result_width = $thumb_height * $source_ratio;    }    // Ratio is Wider    elseif ($thumb_ratio < $source_ratio)    {      $result_width = $thumb_width;      $result_height = $thumb_width / $source_ratio;    }    // Ratio the Same    elseif($thumb_ratio == $source_ratio)    {      $result_height = $thumb_height;      $result_width = $thumb_width;    }     return array('x'=>$result_width,'y'=>$result_height);  }   /* ----------[ func IMAGE_RESIZE ]----------*/  function image_resize_jpg($image = FALSE,                            $filename = FALSE,                            $thumb_width,                            $thumb_height,                            $maximize = FALSE,                            $quality = 75,                            $image_object = FALSE)  {    if (is_resource($image_object) === true)    {      $source_width = imagesx($image_object);      $source_height = imagesy($image_object);      $thumb_source = $image_object;    }    else    {      list($source_width, $source_height, $source_type) = @getimagesize($image);      switch($source_type)      {        case 1:          $thumb_source = imagecreatefromgif($image);          break;        case 2:          $thumb_source = imagecreatefromjpeg($image);          break;        case 3:          $thumb_source = imagecreatefrompng($image);          break;        default:          return false;          break;       }    }     if ($maximize === TRUE)    {       $target_width = $thumb_width;      $target_height = $thumb_height;       if ($thumb_width && ($source_width < $source_height))      {         $thumb_width = ($thumb_height / $source_height) * $source_width;      }      else      {         $thumb_height = ($thumb_width / $source_width) * $source_height;      }       if ($thumb_height < $target_height)      {        $multiply_height = $target_height / $thumb_height;        $thumb_height = $thumb_height * $multiply_height;        $thumb_width = $thumb_width * $multiply_height;      }      if ($thumb_width < $target_width)      {        $multiply_width = $target_width / $thumb_width;        $thumb_height = $thumb_height * $multiply_width;        $thumb_width = $thumb_width * $multiply_width;      }       $thumb_height = ceil($thumb_height);      $thumb_width = ceil($thumb_width);     }    else if ($source_width > $thumb_width or $source_height > $thumb_height)    {       $dimensions = image_resize_dimensions($source_width,$source_height,$thumb_width,$thumb_height);      $thumb_width = $dimensions['x'];      $thumb_height = $dimensions['y'];      $target_width = $dimensions['x'];      $target_height = $dimensions['y'];     }    else // Resize Nothing    {      $thumb_width = $source_width;      $thumb_height = $source_height;      $target_width = $source_width;      $target_height = $source_height;    }     $thumb_image = imagecreatetruecolor($thumb_width,$thumb_height);       //imagecopyresampled($thumb_image, $thumb_source, 0, 0, 0, 0, $thumb_width, $thumb_height, $source_width, $source_height);    fastimagecopyresampled($thumb_image, $thumb_source, 0, 0, 0, 0, $thumb_width, $thumb_height, $source_width, $source_height);     $target_image = imagecreatetruecolor($target_width,$target_height);    imagecopy ($target_image, $thumb_image, 0, 0, ($thumb_width - $target_width)/2, ($thumb_height - $target_height)/2, $target_width , $target_height);     if($filename === FALSE)    {      unset($thumb_image);      return array('file'=>$filename,                   'width'=>$target_width,                   'height'=>$target_height,                   'quality'=>$quality,                   'type'=>$source_type,                   'object'=>$target_image                   );    }    else    {      imagejpeg($target_image,$filename,$quality);      unset($target_image,$thumb_image);      return array('file'=>$filename,                   'width'=>$target_width,                   'height'=>$target_height,                   'quality'=>$quality,                   'type'=>$source_type                   );    }  }          function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)        {                // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.                // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".                //  Typically from 30 to 60 times faster when reducing high resolution  images down to thumbnail size using the default quality setting.                // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.                //                // Optional "quality" parameter (defaults is 3).  Fractional values are allowed, for example 1.5.                // 1 = Up to 600 times faster.  Poor results, just uses imagecopyresized but removes black edges.                // 2 = Up to 95 times faster.  Images may appear too sharp, some people may prefer it.                // 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled.                // 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.                // 5 = No speedup.  Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled.                        if (empty($src_image) || empty($dst_image)) { return false; }                if ($quality <= 1) {                 $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);                 imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);                 imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);                 imagedestroy ($temp);                } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {                 $tmp_w = $dst_w * $quality;                 $tmp_h = $dst_h * $quality;                 $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);                 imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);                 imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);                 imagedestroy ($temp);                } else {                 imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);                }                return true;        } ?>

    [/hide]

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!