Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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
Trades: 0
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
 
 
Register now for full access!
Old 05-26-2008, 02:17 PM Re: check if there's enough memory before GD execution
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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.";

__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

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
Web Design Made Simple

Posts: 1,228
Trades: 0
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
Web Design Made Simple

Posts: 1,228
Trades: 0
<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
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by VirtuosiMedia View Post
<sigh>
I second that
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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"
__________________
Only a biker knows why a dog sticks his head out the window.

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

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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++
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Do not use GD to resize images, use ImageMagick
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

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 Search this Thread
Search this Thread:

Advanced Search

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 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.26687 seconds with 12 queries