• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory Exhausted when trying to resize

#1
[eluser]metamorpher[/eluser]
I know this is an error for my server only, but I already modified my php.ini and assigned 512MB of the memory to process scripts, so I don't know why I have this problem, when for example I can process larger images (file size and image size) with such a blog tool like wordpress using just 8MB.

So, in detail, I put first the error

Code:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1280 bytes) in
/Applications/MAMP/frameworks/codeigniter2/libraries/Image_lib.php on line 1155

Now, How I do the upload:

Code:
$up_config['file_name'] = time();
    $up_config['upload_path'] = MAINPATH . 'uploads/'; // MAINPATH is a constant I defined myself.
    $up_config['allowed_types'] = 'jpg';
    $up_config['max_size'] = '2048';
    $this->load->library('upload', $up_config);
    if($this->upload->do_upload('photo'))
    {
        $upload = $this->upload->data();
        $this->random_tools_model->generate_thumbnail($upload['full_path'], 200);
    }

and here's the thumbnail generator:

Code:
function generate_thumbnail($img_path_file, $size)
    {
        
        $this->load->library('image_lib');

        $img_data = $this->image_lib->get_image_properties($img_path_file, TRUE);

        if($img_data['width'] > $img_data['height'])
        {
            $conf['height'] = $size;            
        }
        else if($img_data['width'] < $img_data['height'])
        {
            $conf['width'] = $size;
        }

        $conf['source_image']    = $img_path_file;
        $conf['maintain_ratio'] = TRUE;
        $conf['image_library']    = 'gd2';

        if(!$this->image_lib->resize())
        {
            return false;
        }

        $this->image_lib->clear();

        return true;
    }

The max size it can process is like 600 px per 600 px

As I said, don't know why... I haven't had this problem with other scripts nor prior frameworks... I just moved to CI 2... Formerly I was using CI 1.7.

Can you help me at all?

Thank you in advance fellas Smile

#2
[eluser]metamorpher[/eluser]
Well I figured out what the problem was.

I just had to call the clear function after the get_image_properties function.

That's it.. so if you have the same problem, you can know how to solve it:

Here's the final sketch of the generate_thumbnail function:

Code:
function generate_thumbnail($img_path_file, $size)
    {
        
        $this->load->library('image_lib');

        $img_data = $this->image_lib->get_image_properties($img_path_file, TRUE);

        // HERE'S THE BAD BOY WE WERE LOOKIN' FOR
        $this->image_lib->clear();

        if($img_data['width'] > $img_data['height'])
        {
            $conf['height'] = $size;            
        }
        else if($img_data['width'] < $img_data['height'])
        {
            $conf['width'] = $size;
        }

        $conf['source_image']    = $img_path_file;
        $conf['maintain_ratio'] = TRUE;
        $conf['image_library']    = 'gd2';

        if(!$this->image_lib->resize())
        {
            return false;
        }

        $this->image_lib->clear();

        return true;
    }

#3
[eluser]InsiteFX[/eluser]
You can also add more memory in php.ini

InsiteFX

#4
[eluser]metamorpher[/eluser]
As I told in the start on the topic, I already gave 512 MB of memory to the script compiler... Don't you think is crazy to keep giving it more? I don't know how hosting companies work with cloud computing, but my purpose is completely for development, not for production.

#5
[eluser]Drew J[/eluser]
I'm having this problem also. I'm giving PHP 96MB to work with... I'm uploading a 5MB JPG and it gives me a fatal error trying to allocate over 100MB.

I've included $this->image_lib->clear(); after any resize I do.

Anyone else have any more experience with this?

#6
[eluser]walletwallet[/eluser]
i dong't know how to used this forum


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.