Severin Kacianka: Probleme mit dem Memory Limit bei der Thumbnailerstellung

Beitrag lesen

Hallo liebes Forum,

ich versuche mich gerade an der Thumbnailerstellung von hochgeladenen (jpg-)Bildern und erschöpfe jedes Mal das Memory Limit. Als Input verwende ich im Moment ca. 1,4MB große Bilder.
Hier der relevante Code:

  
function createThumb($src,$dest,$new_w,$new_h){  
    $src = imagecreatefromjpeg($src);#Zeile 583  
    $old_x = imageSX($src);  
    $old_y = imageSY($src);  
    if ($old_x > $old_y) {  
        $thumb_w = $new_w;  
        $thumb_h = $old_y * ($new_h / $old_x);  
    }  
    if ($old_x < $old_y) {  
        $thumb_w = $old_x * ($new_w / $old_y);  
        $thumb_h = $new_h;  
    }  
    if ($old_x == $old_y) {  
        $thumb_w = $new_w;  
        $thumb_h = $new_h;  
    }  
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);  
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);  
    imagejpeg($dest_img,$dest);  
    imagedestroy($dst_img);  
    imagedestroy($src_img);  
}  

(Ist fast eine Kopie von http://www.icant.co.uk/articles/phpthumbnails/)
Der Aufruf sieht so aus:

  
<?php  
ini_set("memory_limit","20M");  
include $_SERVER['DOCUMENT_ROOT'].'/includes/datenbank_funktionen.inc.php';  
#echo (int)getWidth('gallerie/9/1.jpg',150);  
echo '<br>'.memory_get_usage();  
createThumb('gallerie/9/1.jpg','gallerie/9/thumb_1.jpg',112,150);  
?>  

Die Ausgabe sieht in etwa so aus:
298984
Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 1944 bytes) in /home/severin/ius/includes/datenbank_funktionen.inc.php on line 583

Die "Googlelösung" ist einfach das memory_limit so hoch wie möglich stellen, aber wenn 20MB nicht reichen, mache ich irgendeinen Fehler.

Was landet alles im Speicher? Bei 20MB Memory_Limit müsste ich doch locker zehn 1,4MB große Bilder unterbringen können?

Gruß und danke für eure Zeit,
Severin

--
They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.
-- Benjamin Franklin