Einzelnen Beitrag anzeigen

Benutzerbild von Matze
Matze
(Co-Admin)

Registriert seit: 7. Jul 2003
Ort: Schwabenländle
14.929 Beiträge
 
Turbo Delphi für Win32
 
#1

[PHP] Memory-Leak oder woran liegt's?

  Alt 9. Sep 2007, 08:45
Hallo zusammen,

ich habe vor einiger Zeit ein kleines PHP-Album gebastelt, doch tritt nun dieser Fehler auf, nachdem ich neue Bilder hinzugefügt habe:

Zitat:
Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 9792 bytes) in /home/www/web6/html/main/functions/fcts_album.php on line 699
Die Funktion, in der der Fehler auftritt, ist diese:

Code:
function create_album_thumbnail($filename)
{
   $im_size = getimagesize($filename);
   $width = $im_size[0];
   $height = $im_size[1];
   $type = $im_size[2];

   unset($im_size);

   $im_thumb_height = 147;
   $im_thumb_small_height = 80;

   // thumbnail size
   if ($width > $height)
   {
      $im_thumb_width = round($width / $height * $im_thumb_height);
      $im_thumb_small_width = round($width / $height * $im_thumb_small_height);
   }
   else
   {
      $im_thumb_width = round($width / $height * $im_thumb_height);
      $im_thumb_small_width = round($width / $height * $im_thumb_small_height);
   }

   $im_thumb = imagecreatetruecolor($im_thumb_width, $im_thumb_height);
   $im_thumb_small = imagecreatetruecolor($im_thumb_small_width, $im_thumb_small_height);

   // set permissions
   //chmod(dirname($filename), 0777);

   switch ($type)
   {
      case 1:
         $im = imagecreatefromgif($filename);
         $im_small = imagecreatefromgif($filename);
         break;
      case 2:
         $im = imagecreatefromjpeg($filename);              // <== Zeile 699
         $im_small = imagecreatefromjpeg($filename);
         break;
      case 3:
         $im = imagecreatefrompng($filename);
         $im_small = imagecreatefrompng($filename);
         break;
      case 4:
         $im = imagecreatefromwbmp($filename);
         $im_small = imagecreatefromwbmp($filename);
         break;
   }

   imagecopyresampled($im_thumb, $im, 0, 0, 0, 0, $im_thumb_width, $im_thumb_height, $width, $height);
   imagecopyresampled($im_thumb_small, $im_small, 0, 0, 0, 0, $im_thumb_small_width, $im_thumb_small_height, $width, $height);

   ImageDestroy($im);
   ImageDestroy($im_small);

   // create thumbnail directory
   $dir = dirname($filename) . '/thumbnails/';
   $dir_small = dirname($filename) . '/thumbnails/small/';
   
   //umask(0);
   if (! file_exists($dir))
   {
      mkdir($dir, 0777);
   }

   if (! file_exists($dir_small))
   {
      mkdir($dir_small, 0777);
   }

   switch ($type)
   {
      case 1:
         imagegif($im_thumb, $dir . basename($filename));
         imagegif($im_thumb_small, $dir_small . basename($filename));
         break;
      case 2:
         imagejpeg($im_thumb, $dir . basename($filename), 75);
         imagejpeg($im_thumb_small, $dir_small . basename($filename), 75);
         break;
      case 3:
         imagepng($im_thumb, $dir . basename($filename));
         imagepng($im_thumb_small, $dir_small . basename($filename));
         break;
      case 4:
         imagewbmp($im_thumb, $dir . basename($filename));
         imagewbmp($im_thumb_small, $dir_small . basename($filename));
         break;
   }

   ImageDestroy($im_thumb);
   ImageDestroy($im_thumb_small);
}
Auch wenn ich zuerst das größere Thumbnail erstelle, das freigeben und danach das kleinere, tritt das gleiche Problem auf. Ich kann nirgendwo ein Memory-Leak entdecken.
Was mache ich falsch?
  Mit Zitat antworten Zitat