Welcome Guest, Not a member yet? Register   Sign In
Thumbs creation with Image Library - Problem
#11

[eluser]Soares[/eluser]
All right. So, my localhost is running under a MAC OS X. I'm using MAMP. The webserver runs under some linux distribution (I can't be sure which one).

Jedd, I have no access to the original php.ini file of the server. What I was told to do (by the webserver employee) is to put my own php.ini file in my public_html folder. Well, if I put the MAMP php.ini, it will launch a bunch of errors. For this reason, I made a php.ini file containing only the settings I wanted to be modified. Which is:

Code:
max_execution_time = 200
memory_limit = 500M
upload_max_filesize = 10M
error_reporting  =  E_ALL
display_errors = On

There aren't two files. What the script is doing is: I upload one image and, with this one image, I create two thumbnails. As I said, if I change the order of which thumbnail (mini or big) is created, it is always the *first* that is created.

Xeoncross, I'm indeed using AJAX to do this. I'm using SWFUpload, but I can't see why the problem would be related with this. The debug mode is turned on and, as you saw in the script I posted, if something goes wrong, it will echo the error.

Code:
if ( ! $this->image_lib->resize())
        {
            echo "Erro:".$this->image_lib->display_errors();
        }
        else
        {
            echo "OK";
        }

But nothing appears in the debug window. Only an 'OK'.
display_errors is set to On. And the log isn't reporting any errors:

Code:
DEBUG - 07-09-2009 18:06:22 --> Native_session Class Initialized
DEBUG - 07-09-2009 18:06:22 --> Figuring Out Session ID automagically
DEBUG - 07-09-2009 18:06:22 --> Database Driver Class Initialized
DEBUG - 07-09-2009 18:06:22 --> DX Auth Initialized
DEBUG - 07-09-2009 18:06:22 --> Config file loaded: config/dx_auth.php
DEBUG - 07-09-2009 18:06:22 --> Language file loaded: language/pt-br/dx_auth_lang.php
DEBUG - 07-09-2009 18:06:22 --> Controller Class Initialized
DEBUG - 07-09-2009 18:06:22 --> Session class already loaded. Second attempt ignored.
DEBUG - 07-09-2009 18:06:22 --> Helper loaded: form_helper
DEBUG - 07-09-2009 18:06:22 --> Session class already loaded. Second attempt ignored.
DEBUG - 07-09-2009 18:06:22 --> Model Class Initialized
DEBUG - 07-09-2009 18:06:22 --> Upload Class Initialized
DEBUG - 07-09-2009 18:06:22 --> Image Lib Class Initialized
DEBUG - 07-09-2009 18:06:22 --> [painel_acoes] Classe inicializada

About the php.ini file, what do you guys think about putting the MAMP php.ini and then strip off all the lines the causes errors (which I think is a lot)?
#12

[eluser]Xeoncross[/eluser]
Ok, that AJAX is what I thought you were using. Instead of printing out an error you should be doing something like

Code:
trigger_error($this->image_lib->display_errors());

So that you can see the details about the resize error (in the log) even if your browser is doing all this in the background with ajax. I don't remember with SWFUpload, but screen prints don't usually do anything in AJAX as that text is never shown to the user.

Also, the log your looking at is the CI log - not the PHP log. Find the PHP error log and look at that as it will actually have useful information in it.

Oh, and error reporting should be more aggressive like this so that you can spot bad coding habits before you end up with weird bugs.
Code:
error_reporting = E_ALL | E_NOTICE | E_STRICT
#13

[eluser]Soares[/eluser]
Following Xeoncross directions, it ended up working. I'm not sure why, but it did.

This is my original code (the one I start this post with):

Code:
function criarThumbs($info)
    {
        $this->load->library('image_lib');
        $config['image_library']     = 'gd2';
        $config['source_image']     = $info['full_path'];
        $config['create_thumb']     = TRUE;
        $config['maintain_ratio']     = TRUE;

        // mini_thumb
        $config['new_image']     = $info['file_path'] . '_mini_thumbs/'; // sem dizer o nome do arquivo. É automático.
        $config['width']         = 150;
        $config['height']         = 120;
        $config['quality']         = 100;

        $this->image_lib->initialize($config);
        log_message('debug', '[painel_acoes] Classe inicializada');
        echo "\nCriando mini_thumb: ";
        if ( ! $this->image_lib->resize())
        {
            echo "Erro:".$this->image_lib->display_errors();
        }
        else
        {
            echo "OK";
        }

        $this->image_lib->clear();

        // big_thumb
        $config['new_image']     = $info['file_path'] . '_big_thumbs/';
        
        $width = 600;
        $height = 500;
        $config['width']        = $width;
        $config['height']         = $height;
        $config['quality']         = 100;
        
        $this->image_lib->initialize($config); // novas configurações do big_thumb.
        echo "\nCriando big_thumb: ";
        if ( ! $this->image_lib->resize())
        {
            echo "Erro:".$this->image_lib->display_errors();
        }
        else
        {
            echo "OK";
        }
    }

After making some updates:

Code:
function criarThumbs($info)
    {
        $this->load->library('image_lib');
        $config['image_library']     = 'gd2';
        $config['source_image']     = $info['full_path'];
        $config['create_thumb']     = TRUE;
        $config['maintain_ratio']     = TRUE;

        // mini_thumb
        $config['new_image']     = $info['file_path'] . '_mini_thumbs/'; // sem dizer o nome do arquivo. É automático.
        $config['width']         = 150;
        $config['height']         = 120;
        $config['quality']         = 100;

        $this->image_lib->initialize($config);
        log_message('debug', '[painel_acoes] Classe inicializada');
        log_message('debug', '[painel_acoes] Criando mini_thumb');
        if ( ! $this->image_lib->resize())
        {
            log_message('error', $this->image_lib->display_errors());
        }
        else
        {
            echo "OK";
            log_message('debug', '[painel_acoes] mini_thumb: OK ');
        }

        $this->image_lib->clear();
        

        // big_thumb
        $config['new_image']     = $info['file_path'] . '_big_thumbs/';
        
        $width = 600;
        $height = 500;
        $config['width']        = $width;
        $config['height']         = $height;
        $config['quality']         = 100;
        
        $this->image_lib->initialize($config); // novas configurações do big_thumb.
        log_message('debug', '[painel_acoes] Classe 2 inicializada');
        log_message('debug', '[painel_acoes] Criando big_thumb');
        if ( ! $this->image_lib->resize())
        {
            log_message('error', $this->image_lib->display_errors());
        }
        else
        {
            echo "OK";
            log_message('debug', '[painel_acoes] big_thumb: OK ');
        }
    }

Basically, what I did was substituting some echos with a log function. The error part, for example, I changed echo for log_message.

Now, why would it influence the behavior of the script? I really don't know. After all, the first one, with all those echos, was perfectly working in my localhost.

Well.. Once done the above updates, I came back to those settings in the php.ini file.
Tried with:

Code:
max_execution_time = 15
memory_limit = 10M
and
Code:
max_execution_time = 200
memory_limit = 10M

None of this worked out. Than I tried this:

Code:
max_execution_time = 15
memory_limit = 100M
And it worked.

Making some tests, I figured that memory_limit should be as high as the images dimensions you are intending to upload.
Since I'm planning to let people upload pictures of until 3000x2500, I set memory_limit to 50MB. I'm not sure if that's the correct value for this dimensions, but it worked in my tests here.
I'm not sure either if these conclusions are correct, but at least it seems.

Jedd and Xeoncross, thanks a lot for your help!




Theme © iAndrew 2016 - Forum software by © MyBB