Jump to content

PHP GD Functions and Max Memory


GregL83

Recommended Posts

I created an image handling script.  So far it works well; however, when I try to upload a bitmap / bmp file all hell breaks loose.

 

The file properties are as follows:

extension: .bmp

size: 425,122 bytes

width: 430 px

height: 329 px

horizontal res: 96 dpi

vertical res: 96 dpi

bit depth: 24

 

I recieve the following error:

Allowed memory size of 18874368 bytes exhausted (tried to allocate 16973 bytes)

 

To uncompress or load the image I use the following:

private function open_image($file){
	# Php.ini Fixes
	ini_set('memory_limit', '128M');
	ini_set('gd.jpeg_ignore_warning', 1);

	# Find correct image type and return image object
	# JPEG:
	$image = imagecreatefromjpeg($file);
	if($image){return $image;}
	# GIF:
	$image = imagecreatefromgif($file);
	if($image){return $image;}
	# PNG:
	$image = imagecreatefrompng($file);
	if($image){return $image;}
	# GD File:
	$image = imagecreatefromgd($file);
	if($image){return $image;}
	# GD2 File:
	$im = imagecreatefromgd2($file);
	if($image){return $image;}
	# WBMP:
	$image = imagecreatefromwbmp($file);
	if($image){return $image;}
	# XBM:
	$image = imagecreatefromxbm($file);
	if($image){return $image;}
	# XPM:
	$image = imagecreatefromxpm($file);
	if($image){return $image;}
	# Try and load from string:
	$image = imagecreatefromstring(file_get_contents($file));
	if($image){return $image;}
	return false;
}

 

I understand that in the php.ini file you have a memory limit for a particular function.  Mine was set to 18M.  I changed it to 128M in the php.ini file and the ini_set function in the code above.  Now, I get an error:

Out of memory (allocated 81264640) (tried to allocate 16973 bytes)

 

I can't figure out why a 430kb image needs 81+Mb to resize and save.  This makes no sense.  Also, this only happens with .bmp files.  Any GD gurus?

 

 

Please help!!  ???

Link to comment
Share on other sites

I tried uploading another bitmap and ran into a different error.  The page seems to hang and never returns an error, but no image upload...

 

This is so f'n annoying.  Nothing is worse than having the app work fine on your local machine and then it blow up online.

Link to comment
Share on other sites

I downloaded a larger jpeg file. The properties are as follows...

 

ext: .jpg

size: 3.71 MB

w: 3648 px

h: 2736

h-res: 72 dpi

v-res: 72 dpi

bit-depth: 24

 

This image also won't upload correctly!!!!! WTF.

Out of memory (allocated 80740352) (tried to allocate 65496 bytes)

 

If this is a hosting issue, than I am done with PowWeb. Period.  I have had so many issue with them screwing up my settings or speaking with techies that know absolutely nothing.

 

Why is a 3.71 MB file using 80 megs for a simple resize?  Plus the 400kb .bmp file?? This is insane.

 

I currently have my max mem set to 300M.........

Link to comment
Share on other sites

Me neither... I was wondering if there is a memory leak or something.  I have done the calculations and a uncompressed version should not come near 50MB let alone 80+.

 

I am speaking with my web host now and trying to find out how to install a php extension i.e. imagick.  I have never installed an extension and the instructions look like chinese to me... Any simple informative guides not from php.net or pecl?

Link to comment
Share on other sites

Yep, all you need is the php extension. Have you checked to see if it's already there with phpinfo()?

 

If it's not I'll have to pass, I don't use cpanel a lot. There should be plenty of guides out there though and I suspect it's faurly simple once you find the right area in cpanel.

Link to comment
Share on other sites

yea... no its not installed.

 

I downloaded the imagick-2.2.1 but I don't have a .dll file... I am wondering if I might need to compile this or something? I have never done anything like that before.

 

The installation instructions I have found are definately not for noobs...

Link to comment
Share on other sites

Sounds like you got problems setting it up locally?

Under openSUSE it's complete easymode.. so if nothing else works you might want to install that (optionally under VMWare/VirtualBox).

It's selecting the "LAMP" pattern during install (or later on under software management) and then simply clicking the one click installer on webpin

 

edit:

Oh right, I forgot to mention you'd need to restart apache afterwards do detect the changes but executing "rcapache2 restart" as root isn't too hard ;)

 

edit 2

Must have been reading too fast, and assumed things based on the .dll you posted. There is no .dll's on an unix platform.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.