phpbar.de logo

Mailinglisten-Archive

[php] GD Lib, gif, jpg

[php] GD Lib, gif, jpg

A. Fridhi mailing at scriptfabrik.com
Mit Okt 15 11:32:15 CEST 2003


Habe die Funktion vergessen:

function saveThumbnail($imgfile,$thfile,$max_width="100",$max_height="100")
{
  global $GD_VER, $IMG_QUALITY;
  list($org_width, $org_height, $orgtype) = getimagesize($imgfile);
  if ($max_width < $org_width)
    $div_width = $org_width / $max_width;
  else
    $div_with = 1;
  if ($max_height < $org_height)
    $div_height = $org_height / $max_height;
  else
    $div_height = 1;

  if ($div_width >= $div_height)
  {
    if ($max_width < $org_width)
      $new_width = $max_width;
    else
      $new_width = $org_width;
    $new_height = round($org_height / $div_width);
  }
  else
  {
    if ($max_height < $org_height)
      $new_height = $max_height;
    else
      $new_height = $org_height;
    $new_width = round($org_width / $div_height);
  }

  switch ($orgtype)
  {
    case 1 :
      $im = imagecreatefromgif($imgfile);
      break;
    case 2 :
      $im = imagecreatefromjpeg($imgfile);
      break;
    case 3 :
      $im = imagecreatefrompng($imgfile);
      break;
  }
  if ($im)
  {
    $tn = imagecreatetruecolor($new_width,$new_height);
    if ($tn)
    {

imagecopyresized($tn,$im,0,0,0,0,$new_width,$new_height,$org_width,$org_heig
ht);
      switch ($orgtype)
      {
        case 1 :
          imagegif($tn,$thfile);
          return 1;
          break;
        case 2 :
          imagejpeg($tn,$thfile,$IMG_QUALITY);
          return 2;
          break;
        case 3 :
          imagepng($tn,$thfile);
          return 3;
          break;
      }
    }
  }
  return false;
}

Phpinfo sagt zum Thema GD:
      GD Support  enabled
      GD Version  2.0 or higher
      FreeType Support  enabled
      FreeType Linkage  with freetype
      GIF Read Support  enabled
      GIF Create Support  enabled
      JPG Support  enabled
      PNG Support  enabled
      WBMP Support  enabled


Würde mich über Hilfe freuen !
Danke Alexander




php::bar PHP Wiki   -   Listenarchive