Fatal error: Allowed memory size
| From: | Shashin | Date: | Wed, 26 Nov 2003 20:43:35 +0000 |
| Subject: | Fatal error: Allowed memory size | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-171129@lists.php.net to get a copy of this message | ||
I am using the PHP GD functions to resize my images.
I get the following error when trying to resize multiple images. It works
for one image.
-------------------------------------------------------------------------
Fatal error: Allowed memory size of 20971520 bytes exhausted at (null):0
(tried to allocate 6816 bytes) in file
-------------------------------------------------------------------------
PHP Config is
-------------------------------------------------------------------------
'./configure' '--includedir=/usr/include' '--libdir=/usr/lib'
'--libexecdir=/usr/libexec' '--enable-force-cgi-redirect'
'--enable-pic'
'--disable-rpath' '--enable-wddx--enable-inline-optimization'
'--with-bz2'
'--with-curl' '--with-dom=/usr' '--with-freetype-dir=/usr'
'--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf'
'--with-ttf'
'--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp'
'--with-jpeg-dir=/usr' '--with-openssl' '--with-png'
'--with-pspell'
'--with-regex=system' '--with-xml' '--with-expat-dir=/usr'
'--with-zlib'
'--with-layout=GNU' '--enable-bcmath' '--enable-debugger'
'--enable-exif'
'--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode'
'--enable-sockets' '--enable-sysvsem' '--enable-sysvshm'
'--enable-discard-path' '--enable-track-vars' '--enable-ucd-snmp-hack'
'--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath'
'--enable-shmop' '--enable-versioning' '--enable-calendar'
'--enable-dbx'
'--enable-dio' '--enable-mbstring' '--enable-mbstr-enc-trans'
'--with-apxs=/usr/local/apache/bin/apxs' '--enable-trans-sid'
'--enable-yp'
'--with-mysql=/usr'
-------------------------------------------------------------------------
The function i am using is below
-------------------------------------------------------------------------
function Resize_Image_File ($Source_File, $Target_File, $Proportionate =
"yes", $Target_Height = "60", $Target_Width = "60", $Jpeg_Quality =
"75") {
// Get the dimensions of the source picture
$Picture_Size = getimagesize("$Source_File");
$Source_File_Width = $Picture_Size[0];
$Source_File_Height = $Picture_Size[1];
if (preg_match("/gif/i", $Source_File)) {
$Source_File = imagecreatefromgif("$Source_File");
} else if (preg_match("/jpg|jpeg/i", $Source_File)) {
$Source_File = imagecreatefromjpeg("$Source_File");
} // end of if statement checking for images.
// we will contrain proportions for an image when not specified.
if ($Proportionate == "yes")
$Target_Height = (int)floor($Source_File_Height * $Target_Width /
$Source_File_Width);
// Create a new image object
$Target_Blank_File = imagecreatetruecolor($Target_Width, $Target_Height);
// Resize the original picture and copy it into the just created image
object.
// We will create a progressive jpeg
imageinterlace ($Target_Blank_File,1);
$Target_File_Final = imagecopyresampled($Target_Blank_File, $Source_File, 0,
0, 0, 0, $Target_Width, $Target_Height, $Source_File_Width,
$Source_File_Height);
$Create_JPEG = imagejpeg ($Target_Blank_File, "$Target_File",
$Jpeg_Quality);
imagedestroy ($Source_File);
imagedestroy ($Target_Blank_File);
imagedestroy ($Target_File_Final);
} // end of function resize image file