Bluehost.com Web Hosting $6.95

Fatal error: Allowed memory size

This is a discussion on Fatal error: Allowed memory size within the PHP General forums, part of the PHP Programming Forums category; I am using the PHP GD functions to resize my images. I get the following error when trying to resize ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-26-2003
Shashin
 
Posts: n/a
Default Fatal error: Allowed memory size

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
Reply With Quote
  #2 (permalink)  
Old 11-27-2003
David Otton
 
Posts: n/a
Default Re: [PHP] Fatal error: Allowed memory size

On Wed, 26 Nov 2003 12:43:35 -0800, you wrote:

Ok, please bear in mind that I've never run into this, so what follows if
guesswork.

>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
>'--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath'


You say it fails on multiple images. How many? Can it process 2, 3, etc? If
so, my guess would be that a memory leak in the GD lib is causing the script
to bump into it's memory_limit:

http://uk.php.net/manual/en/configur...i.memory-limit

If it can only process one image, I'd look for an error in your script.

Some questions that might help you get a better answer: Which PHP version?
OS? GD Lib version? How big are your original image files? What does
memory_get_usage() return after the first, second pass etc?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0