473,587 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

100KB image that takes up 2mb of memory uses up all 8mb of memory - help!

I have an image that's only 100K in size, and I am working with 8mb of
memory. If I do this:

[PHP]
print_r(ceil((i nt)ini_get('mem ory_limit') * 10 *
filesize(actual _path("$locatio nPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_conte nts(actual_path (realpath("$loc ationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to me
that the memory allotment of 8mb has been used up).

How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Thanx
Phil

Sep 25 '06 #1
6 2099
On 25 Sep 2006 13:41:02 -0700, "comp.lang. php" <ph************ **@gmail.com>
wrote:
>I have an image that's only 100K in size, and I am working with 8mb of
memory. If I do this:

[PHP]
print_r(ceil(( int)ini_get('me mory_limit') * 10 *
filesize(actua l_path("$locati onPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]
Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file, doesn't that
mean your memory_limit is set to "2" ? (presumably "2M", turning into "2" after
the cast to int).
>The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_cont ents(actual_pat h(realpath("$lo cationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to me
that the memory allotment of 8mb has been used up).
That seems like a guess... what error messages do you get? If you can't see
them, change the content-type of the output back to text.
>How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
of memory on file_get_conten ts() alone? I'm completely confused!
Why would a 100KB image use 2MB? Where did 8MB come from? I'm also confused...

The usual pitfall is that a 100KB image can easily decompress to several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 25 '06 #2

Andy Hassall wrote:
On 25 Sep 2006 13:41:02 -0700, "comp.lang. php" <ph************ **@gmail.com>
wrote:
I have an image that's only 100K in size, and I am working with 8mb of
memory. If I do this:

[PHP]
print_r(ceil((i nt)ini_get('mem ory_limit') * 10 *
filesize(actual _path("$locatio nPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file, doesn't that
mean your memory_limit is set to "2" ? (presumably "2M", turning into "2" after
the cast to int).
Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefrom jpeg, or
imagecreatefrom gif or imagecreatefrom png.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"
The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_conte nts(actual_path (realpath("$loc ationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to me
that the memory allotment of 8mb has been used up).

That seems like a guess... what error messages do you get? If you can't see
them, change the content-type of the output back to text.
I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php
>
How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Why would a 100KB image use 2MB? Where did 8MB come from? I'm also confused...
Sorry but I have no idea whatsoever. Can someone else elaborate?
>
The usual pitfall is that a 100KB image can easily decompress to several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 26 '06 #3
Andy

What size is the image you are loading in megaPIXELS?
This is often the limiting factor in PHP GD processing, not the original
size in Kb or the final size in Kb.
When I ran into this I found that PHP stopped abruptly with an error
message.

-- Simon
"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
>
Andy Hassall wrote:
>On 25 Sep 2006 13:41:02 -0700, "comp.lang. php"
<ph*********** ***@gmail.com>
wrote:
>I have an image that's only 100K in size, and I am working with 8mb of
memory. If I do this:

[PHP]
print_r(ceil(( int)ini_get('me mory_limit') * 10 *
filesize(actua l_path("$locati onPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file, doesn't
that
mean your memory_limit is set to "2" ? (presumably "2M", turning into "2"
after
the cast to int).

Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefrom jpeg, or
imagecreatefrom gif or imagecreatefrom png.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"
>The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_cont ents(actual_pat h(realpath("$lo cationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to me
that the memory allotment of 8mb has been used up).

That seems like a guess... what error messages do you get? If you can't
see
them, change the content-type of the output back to text.

I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php
>>
>How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Why would a 100KB image use 2MB? Where did 8MB come from? I'm also
confused...

Sorry but I have no idea whatsoever. Can someone else elaborate?
>>
The usual pitfall is that a 100KB image can easily decompress to several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Sep 26 '06 #4

Simon Stewart wrote:
Andy

What size is the image you are loading in megaPIXELS?
This is often the limiting factor in PHP GD processing, not the original
size in Kb or the final size in Kb.
When I ran into this I found that PHP stopped abruptly with an error
message.
The GIF image is Size: 332 x 287 px = 95284 sq px which is less than
0.1 sq mpx

in other words, a tiny image

Phil
-- Simon
"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@e 3g2000cwe.googl egroups.com...

Andy Hassall wrote:
On 25 Sep 2006 13:41:02 -0700, "comp.lang. php"
<ph************ **@gmail.com>
wrote:

I have an image that's only 100K in size, and I am working with 8mb of
memory. If I do this:

[PHP]
print_r(ceil((i nt)ini_get('mem ory_limit') * 10 *
filesize(actual _path("$locatio nPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file, doesn't
that
mean your memory_limit is set to "2" ? (presumably "2M", turning into "2"
after
the cast to int).
Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefrom jpeg, or
imagecreatefrom gif or imagecreatefrom png.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"
The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_conte nts(actual_path (realpath("$loc ationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to me
that the memory allotment of 8mb has been used up).

That seems like a guess... what error messages do you get? If you can't
see
them, change the content-type of the output back to text.
I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php
>
How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Why would a 100KB image use 2MB? Where did 8MB come from? I'm also
confused...
Sorry but I have no idea whatsoever. Can someone else elaborate?
>
The usual pitfall is that a 100KB image can easily decompress to several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 26 '06 #5
Phil

yes that's far in pixels smaller than when I had problems
the 8Mb memory_limit you have for PHP is low. Hosting companies often
allocate 16 or 32Mb.
have you tried doing memory_get_usag e calls before the problem code? Could
the program or environment be short on memory anyway?

Simon.

"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
>
Simon Stewart wrote:
>Andy

What size is the image you are loading in megaPIXELS?
This is often the limiting factor in PHP GD processing, not the original
size in Kb or the final size in Kb.
When I ran into this I found that PHP stopped abruptly with an error
message.

The GIF image is Size: 332 x 287 px = 95284 sq px which is less than
0.1 sq mpx

in other words, a tiny image

Phil
>-- Simon
"comp.lang.php " <ph************ **@gmail.comwro te in message
news:11******* **************@ e3g2000cwe.goog legroups.com...
>
Andy Hassall wrote:
On 25 Sep 2006 13:41:02 -0700, "comp.lang. php"
<ph*********** ***@gmail.com>
wrote:

I have an image that's only 100K in size, and I am working with 8mb
of
memory. If I do this:

[PHP]
print_r(ceil(( int)ini_get('me mory_limit') * 10 *
filesize(actua l_path("$locati onPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file,
doesn't
that
mean your memory_limit is set to "2" ? (presumably "2M", turning into
"2"
after
the cast to int).
Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefrom jpeg, or
imagecreatefrom gif or imagecreatefrom png.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"

The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_cont ents(actual_pat h(realpath("$lo cationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to
me
that the memory allotment of 8mb has been used up).

That seems like a guess... what error messages do you get? If you
can't
see
them, change the content-type of the output back to text.

I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php
How in the world can a 100KB image that uses only 2mb of 8mb use up
8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Why would a 100KB image use 2MB? Where did 8MB come from? I'm also
confused...

Sorry but I have no idea whatsoever. Can someone else elaborate?

The usual pitfall is that a 100KB image can easily decompress to
several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis
tool

Sep 26 '06 #6

Simon Stewart wrote:
Phil

yes that's far in pixels smaller than when I had problems
the 8Mb memory_limit you have for PHP is low. Hosting companies often
allocate 16 or 32Mb.
have you tried doing memory_get_usag e calls before the problem code? Could
the program or environment be short on memory anyway?
I was suspecting that most places use more than 8mb default memory;
however, it appears customized as our servers here come "out of the
box" with RHEL 4 which sets the memory_limit within php.ini to 8mb.
It's easy to fix that, of course, but just thought I'd share.

I wrote some code that apparently seems to solve the memory issue:

[PHP]
$mem = memory_get_usag e();
list($width, $height) =
@getimagesize(a ctual_path(real path("$this->locationPath/$this->fileName"))) ;
if ($willIncreaseM emory && (int)ini_get('m emory_limit') * 10 *
@filesize(actua l_path("$this->locationPath/$this->fileName")) $mem) {
@ini_set('memor y_limit', ceil((int)ini_g et('memory_limi t') * 10 *
filesize(actual _path("$this->locationPath/$this->fileName")) / 100000)
.. 'M');
} elseif ($willIncreaseM emory && (int)$width 0 && (int)$height >
0) {
@ini_set('memor y_limit', ceil((int)$widt h * (int)$height * 5 /
10000) . 'M');
}
[/PHP]
Simon.

"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@e 3g2000cwe.googl egroups.com...

Simon Stewart wrote:
Andy

What size is the image you are loading in megaPIXELS?
This is often the limiting factor in PHP GD processing, not the original
size in Kb or the final size in Kb.
When I ran into this I found that PHP stopped abruptly with an error
message.
The GIF image is Size: 332 x 287 px = 95284 sq px which is less than
0.1 sq mpx

in other words, a tiny image

Phil
-- Simon
"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@e 3g2000cwe.googl egroups.com...

Andy Hassall wrote:
On 25 Sep 2006 13:41:02 -0700, "comp.lang. php"
<ph************ **@gmail.com>
wrote:

I have an image that's only 100K in size, and I am working with 8mb
of
memory. If I do this:

[PHP]
print_r(ceil((i nt)ini_get('mem ory_limit') * 10 *
filesize(actual _path("$locatio nPath/$this->fileName")) / 1000000) .
'M'); // PRINTS OUT "2M" for 2mb
]/PHP]

Maybe I'm having a dense moment, but what does this value even mean?
memory_limit times 10 times size of file then divided by a million?

Is the output actually "2M" ? If you have a 100,000 byte file,
doesn't
that
mean your memory_limit is set to "2" ? (presumably "2M", turning into
"2"
after
the cast to int).


Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefrom jpeg, or
imagecreatefrom gif or imagecreatefrom png.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"

The image itself requires far less than the maximum amount of memory
required.

However, the moment I do this:

[PHP]
$imagestring =
@file_get_conte nts(actual_path (realpath("$loc ationPath/" .
$this->{$section . '_name'})));
[/PHP]

It locks up and forces a download of "index.php" (which indicates to
me
that the memory allotment of 8mb has been used up).

That seems like a guess... what error messages do you get? If you
can't
see
them, change the content-type of the output back to text.

I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php


How in the world can a 100KB image that uses only 2mb of 8mb use up
8mb
of memory on file_get_conten ts() alone? I'm completely confused!

Why would a 100KB image use 2MB? Where did 8MB come from? I'm also
confused...

Sorry but I have no idea whatsoever. Can someone else elaborate?

The usual pitfall is that a 100KB image can easily decompress to
several
megabytes, and that GD uses even more memory than you might expect.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis
tool
Sep 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
11057
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin =...
2
2441
by: DraguVaso | last post by:
Hi, In the override of the Paint-method of a DataGridTextBoxColumn I want to show an image with BitBlt, to see what I can gain there on performance. The problem is: It doesn't show me the image in the DataGrid-Cell's, but a black background... Does anybody has any idea what I am doing wrong? Thanks a lot in advance,
3
3340
by: CroDude | last post by:
Hi all! I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control. In a thumbnail mouse down event I'm using static method Image.FromFile(string path).Something like this: this.mainApp.pictureBox1.Image = Image.FromFile( imagePath ) Well ... the...
12
6173
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses the DLL above. Now the application, together with the above DLL’s is successfully loading a TIF image file (62992 x 113386 Pixels, Huffman RLE...
7
3384
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
14529
by: | last post by:
Hi, we are planning to rewrite an extisting C++ image processing application/library in C#. Now several question arouse where I hope you can help me: So far we allocated a block of memory as image buffer, handed this to a driver dll and got raw image data back in this buffer. We then handed this buffer by reference to another C++ dll to...
4
3457
by: LT.Ang | last post by:
I am developing an application that possibly opens very large images - bmp, jpeg, tiff. I have 2 questions: Language: C#, VS .NET 2003. 1. When the program opens a BMP image, the amount of memory used seems to be larger for BMP files than JPEGs with the same pixel dimensions. For example, 5200 x 5000 pixels image -- increase in Mem Usage...
11
1519
by: sam_cit | last post by:
Hi Everyone, I'm currently working in embedded environment and hence resources like memory are constrained. And i'm in a need to pass a entire text file to a parser (implemented in lex/yacc) to parse it. The maximum size of the text file is 100kb and i can't allocate a buffer to hold the complete 100 kb of data in memory for the parser to...
1
11062
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of StringIO objects being passed in place of file objects. StringIO objects are binary strings of variable length that are kept in memory so i saved the...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.