2016-10-07 11 views
1

この機能を使用してJpgまたはPngファイルからサムネイルを作成しようとすると、非常に不満な問題が発生しています。メモリサイズを使い果たしました - Imagecreatetruecolour();

時々動作し、ときどき動作しないことがあります。私はメモリリークを持っている必要がありますと思いますが、私はそれを引き起こしているかわからないんだけど、オンラインアップ読め

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8192 bytes) in * on line 34 

:それは動作しない場合は、私は次のエラーを取得します。ここで

機能は次のとおりです。

function make_thumb($src, $dest, $desired_width) { 

    $fileType = pathinfo($src, PATHINFO_EXTENSION); 

    echo $fileType; 

    if ($fileType == 'JPG' || $fileType == 'JPEG' || $fileType == 'jpg' || $fileType == 'jpeg') { 
     $source_image = imagecreatefromjpeg($src); 
    } else if ($fileType == 'PNG' || $fileType == 'png') { 
     $source_image = imagecreatefrompng($src); 
    } else { 
     return false; 
    } 
    $width = imagesx($source_image); 
    $height = imagesy($source_image); 

    $desired_height = floor($height * ($desired_width/$width)); 

    $virtual_image = imagecreatetruecolor($desired_width, $desired_height); 

    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); 

    imagejpeg($virtual_image, $dest); 

    return true; 
} 

ありがとう!

+0

は[imagedestroy](http://php.net/manual/en/function.imagedestroy.php)そのため – jszobody

+0

感謝を参照してください!私はimagecreatetruecolorラインの後、または機能の終わりにそれをまっすぐに置くことができますか? – georgewoofbates

答えて

0

は、コードの先頭にコードを使用します。

ini_set("memory_limit","256M"); 
関連する問題