Note that there are some explanatory texts on larger screens.

plurals
  1. POPNG upload error - allocated memory size error
    primarykey
    data
    text
    <p>I'm trying to upload an image into an application I'm creating. The .png image occupies about 190KB in the file system and the resolution is 2000px wide and 1667 px in height. I have set the memory limit for PHP for 32MB. But when I try to upload this .png image which I believe a lot of the people using my application will do, I'm getting the following error</p> <pre><code>Allowed memory size of 33554432 bytes exhausted (tried to allocate 13336000 bytes) </code></pre> <p>Now when I calculated these into say MB I understood that it read</p> <pre><code>Allowed memory size of 32MB exhausted ( tried to allocate 12.71MB ) </code></pre> <p>So what I don't understand is how come a file which shows a size of 190KB on the file system end up taking up so much memory space? Is it something about how .png files are handled in memory which I don't know about? </p> <p>Here is the code</p> <pre><code>private function optimise_image($source_path, $destination_path){ list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_path); //Using this source path, we'll create a memory instance of the image for processing $source_image_ratio = $source_image_width/$source_image_height; switch ($source_image_type) { case IMAGETYPE_GIF: $source_gd_image = imagecreatefromgif($source_path); break; case IMAGETYPE_JPEG: $source_gd_image = imagecreatefromjpeg($source_path); break; case IMAGETYPE_PNG: $source_gd_image = imagecreatefrompng($source_path); break; } </code></pre> <p>The error is occuring in imagecreatefrompng(). I load the image here to reduce it's resolution and to set it's quality to optimise storage and bandwidth on viewing.</p> <p>Upon investigating a bit further, I found that the file is being uploaded and the size of the file on the server is again 190KB. So the piece of code you're seeing is where it's trying to pick up the file again for processing. Before this there's no where in the process where the file is being loaded into memory once and then left there without being destroyed ( which I thought was what would have been happening )</p> <p>If there is any more information you may require, do ask I and I shall try and answer accordingly.</p> <p>Thanks in advance :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload