# Fatal Error: Allowed memory size

- Thread: https://externals.io/message/5728
- Original archive: https://news-web.php.net/php.internals/5728
- Started by Shashin on 2003-11-26T19:41:55+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5728 — Shashin — 2003-11-26T19:41:55+00:00

URL: https://externals.io/message/5728#5728

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

---

## #5729 — Derick Rethans — 2003-11-26T20:36:13+00:00

URL: https://externals.io/message/5728#5729 · In reply to: #5728

> 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.

This list is not for support questions, please refer to the php-general
list for this.

Derick

---

## #5800 — Andi Gutmans — 2003-11-27T10:46:47+00:00

URL: https://externals.io/message/5728#5800 · In reply to: #5728

At 09:36 PM 11/26/2003 +0100, Derick Rethans wrote:
>
>
> > […]
>
>This list is not for support questions, please refer to the php-general
>list for this.

I told this guy to mail internals@ because it looks like a memory leak.
The script seems to be fine.

Andi

---

## #5801 — Derick Rethans — 2003-11-29T12:11:57+00:00

URL: https://externals.io/message/5728#5801 · In reply to: #5800

> At 09:36 PM 11/26/2003 +0100, Derick Rethans wrote:
> > […]
>
> I told this guy to mail internals@ because it looks like a memory leak.
> The script seems to be fine.

I didn't bother to read that unreadable script without indentation :)

Derick
