Reply
check if there's enough memory before GD execution
Old 05-26-2008, 12:44 PM check if there's enough memory before GD execution
Banned

Posts: 5
Sometimes PHP GD library crashes and leaves a dummy page behind, sometimes the main page goes all blank if you have last uploads thumbnails there being created dynamically. So how do i check if there's enough assigned memory to perform GD execution before calling GD functions?

I think if an image is 1024x768 and has 16bits per pixel the required memory will be about 1,5 MB (12,5 Mb), the question is how do i know how many bits per pixel one image has no matter its format.

Last edited by ehat : 05-26-2008 at 12:48 PM.
ehat is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-26-2008, 02:17 PM Re: check if there's enough memory before GD execution
rogem002's Avatar
Webmaster Talker

Posts: 609
Name: Mike
Location: United Kingdom
http://uk.php.net/manual/en/function...-get-usage.php - Gets the memory usage.

http://uk.php.net/manual/en/function...peak-usage.php - Max amount of memory allowed.

For for example:
PHP Code:
$estimated_amount_of_ram 200;
if((
memory_get_usage() + $estimated_amount_of_ram) >= memory_get_peak_usage()){
echo 
"Sorry not enough ram.";

__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 

Last edited by rogem002 : 05-26-2008 at 02:19 PM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 05-26-2008, 04:23 PM Re: check if there's enough memory before GD execution
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 738
Not a great way to get people to help...

Have you considered multiplying the number of pixels by the number of bytes per pixel and then comparing that number to the amount available memory?
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-26-2008, 11:08 PM Re: check if there's enough memory before GD execution
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 738
<sigh>

Last edited by VirtuosiMedia : 05-27-2008 at 04:28 AM.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-27-2008, 07:04 AM Re: check if there's enough memory before GD execution
rogem002's Avatar
Webmaster Talker

Posts: 609
Name: Mike
Location: United Kingdom
Quote:
Originally Posted by VirtuosiMedia View Post
<sigh>
I second that
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 05-27-2008, 07:13 AM Re: check if there's enough memory before GD execution
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
Quote:
Originally Posted by ehat View Post
Lol, another Einstein...maybe now you can tell me where do i get the famous "bytes per pixel" value
Do your homework, and try to help yourself at least a minimum.
You don't find much more help if you are waiting for us to give you a code snippet.

VirtuosiMedia gave you everything you needed. If you don't understand the answer, ask for details and stop calling your helpers "yet another Einstein"
__________________
Listen to the ducky: "This is awesome!!!"


Last edited by tripy : 05-27-2008 at 07:14 AM.
tripy is offline
Reply With Quote
View Public Profile
 
Old 05-27-2008, 10:11 AM Re: check if there's enough memory before GD execution
rogem002's Avatar
Webmaster Talker

Posts: 609
Name: Mike
Location: United Kingdom
Quote:
Originally Posted by tripy View Post
stop calling your helpers "yet another Einstein"
Quote:
Originally Posted by ehat View Post
ok einsteins, nevermind reaaalllly
Argh! Well said tripy, your Talkupation++
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 05-28-2008, 02:41 AM Re: check if there's enough memory before GD execution
mtishetsky's Avatar
King Spam Talker

Posts: 1,054
Name: Mike
Location: Mataro, Spain
Do not use GD to resize images, use ImageMagick
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to check if there's enough memory before GD execution
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15165 seconds with 12 queries