Welcome Guest, Not a member yet? Register   Sign In
Can't process more than one image.
#1

[eluser]Pawel K[/eluser]
Hello,

I have been struggling with an issue I posted about a week back. It seems after losts of testing I can not process more than one image in a script. Here is my code:

Code:
#Main Image
                    $config['image_library'] = 'gd2';
                    $config['source_image'] = "/home/xxxxxxx/www/cart/images/products/1274642339.jpg";
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = $this->config->item('img_width');
                    $config['height'] = $this->config->item('img_height');
                    $config['new_image'] = "/home/xxxxx/www/cart/images/products/1-image.jpg";
                    
                    
                    $this->load->library('image_lib', $config);
    
                    if ( ! $this->image_lib->resize())
                    {
                       echo "Image 1 errors:".$this->image_lib->display_errors()."<br>";
                    }
                    $this->image_lib->clear();
                    
                    chmod("/home/xxxx/www/cart/images/products/1274643972.jpg", 0777);
                    
                    #Thumb Image
                    $config['image_library'] = 'gd2';
                    $config['source_image'] = "/home/xxxx/www/cart/images/products/1274643972.jpg";
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['width'] = $this->config->item('thumb_width');
                    $config['height'] = $this->config->item('thumb_height');
                    $config['new_image'] = "/home/mesacrea/www/cart/images/products/2-image.jpg";
                    
                    $this->load->library('image_lib', $config);
    
                    if ( ! $this->image_lib->resize())
                    {
                    echo "Image 2 errors:".$this->image_lib->display_errors()."<br>";
                    }
                    $this->image_lib->clear();

This returns the following error for the second image:

Code:
Your server does not support the GD function required to process this type of image.

The first image is created fine.

Does anyone have an idea why this is happening or suggestions on how to process multiple images correctly? Help would be appreciated.
#2

[eluser]Mat-Moo[/eluser]
Try $this->upload->initialize($config) as I'm not sure the 2nd load library will work as the library is already loaded.

edit $this->image_lib->initialize($config); my bad Wink
#3

[eluser]robertvn2k[/eluser]
You can try as follow

//load library
$this->load->library('image_lib');
$this->image_lib->clear();

//set config
$config .....

//initialize
$this->image_lib->initialize($config);

//do resize

...
Repeat the same code with second image.
#4

[eluser]Pawel K[/eluser]
Thanks, that makes sense and seems to have done the trick. I appreciate it.
#5

[eluser]munkeh[/eluser]
I'm having the same problem and the posted solution doesn't work for me.

I'm trying to resize (if image is above a certain size) and also create a thumbnail. I can comment out either section of code and do one or the other but if I attempt to do both it will not work.

Bizarrely the thumbnail creation will work if it's the only thing I do but if I add the resize code afterwards the thumbnail function will fail and I'll have two files. One will be the original filename and large size (the resize will not work) and the other will be filename_thumb.jpg but will be resized to 1280*1024.

Even though both resize and thumbnail creation are failing there are no errors output. Makes no sense to me. It's like the library isn't closing the file before I ask it to reopen the file or something.

Here's my code:
Code:
$this->load->library('image_lib');
$this->image_lib->clear();

$thumb['image_library'] = 'gd2';
$thumb['source_image'] = $upload_data['full_path'];
$thumb['create_thumb'] = TRUE;
$thumb['maintain_ratio'] = TRUE;
$thumb['width'] = 300;
$thumb['height'] = 200;

$this->image_lib->initialize($thumb);
if ( ! $this->image_lib->resize())
{
    echo $this->image_lib->display_errors();
}


$this->image_lib->clear();

if (($upload_data['image_width'] > 1280) || ($upload_data['image_height'] > 1024)) {

    $resize['image_library'] = 'gd2';
    $resize['source_image']    = $upload_data['full_path'];
    $resize['maintain_ratio'] = TRUE;
    $resize['width']     = 1280;
    $resize['height']    = 1024;

    $this->image_lib->initialize($resize);
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
    }

}
#6

[eluser]Mat-Moo[/eluser]
Just use my image_moo lib, much easier than CI lib.
#7

[eluser]munkeh[/eluser]
Wow.

Five minutes later I have the following few lines of code and, more importantly, a working function. Thanks!
Code:
$this->load->library('image_moo');

$this->image_moo->load($upload_data['full_path']);

if (($upload_data['image_width'] > 1280) || ($upload_data['image_height'] > 1024)) {
    $this->image_moo->resize(1280,1024)->save($upload_data['full_path'], $overwrite=TRUE);
}
$this->image_moo->resize(300,200)->save_pa($prepend="", $append="_thumb");

if($this->image_moo->errors) print $this->image_moo->display_errors();

I'm still interested in finding out why the built in library wasn't working so if anyone has any ideas please let me know!

Thanks again.
#8

[eluser]cahva[/eluser]
It is an old bug which I reported long time ago to the old bugtracker(unfortunately old bugtracker is no more) and it's probably the same. Clear method doesnt clear everything and will leave for example create_thumb to TRUE even after using that.

This is probably the same bug that is described here in the new bugtracker.




Theme © iAndrew 2016 - Forum software by © MyBB