Welcome Guest, Not a member yet? Register   Sign In
[solved] help me find a bug with file uploading
#11

[eluser]toopay[/eluser]
My point above is, try to create thumbnail right on resizing process on 'image_resize_for_gallery' function. Of course after that, you wouldn't have to create thumbnail and doing resizing process for that file on 'gallery_thumb' function (give a flag in session). I mean, something like
Code:
// On galery_thumb function
if($some_flag_here != TRUE) $config['create_thumb'] = TRUE;
#12

[eluser]SPeed_FANat1c[/eluser]
Finally it looks taht my code is working.

I placed creating thumbnail before resizing the image (we creating thumbnail anyway). And then I check if the image_width is > 700. If so, then resize. But in resizing function I needed one thing -

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


I remembered that after your last post when you said to create thumbnail at the same function as resizing, I thought I need to pass new config settings, but the library is already loaded.
Code:
function image_resize_for_gallery($album_folder, $image_name)
    {
        
        $config['image_library'] = 'gd2';

        $config['source_image']    = './uploads/gallery/'.$album_folder.'/'.$image_name;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 700;
        $config['height']    = 700;
        
        $this->image_lib->initialize($config);
        
        //$this->load->library('image_lib', $config);

        if ( ! $this->image_lib->resize())
        {
            $this->image_lib->clear();
            return $this->image_lib->display_errors();
        }
        else
        {
            
            $this->image_lib->clear();
            return 'ok';
        }
    }

But it somehow remembers that it is loaded from creating thumbnail or somehow, don't know, since in this function I don't call

$this->load->library

statement.

I have had such problem earlier but only today I remembered, and checked my epitome, and yeah, here it is. I should probably write this on my wall in room in big letters Big Grin

Thank you very much for helping. This was insane problem, because it looks simple, but I took so much time to solve it.
#13

[eluser]SPeed_FANat1c[/eluser]
Hi, actually I noticed that my code is not working how I want - it creates thumnail, rezises the image to be lees than 700 widht, but it creates a copy with ending _thumb and leaves the original. But I want original to be replaced.

Now what I am trying to do:

I don't create a thumbnail, but instead first rezize the image and then create a thumbnail:
Code:
function image_resize_for_gallery($album_folder, $image_name)
    {
        
        $config['image_library'] = 'gd2';

        $config['source_image']    = './uploads/gallery/'.$album_folder.'/'.$image_name;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 700;
        $config['height']    = 700;
        
        echo ($config['source_image']);
        
        
        
        $this->load->library('image_lib');
        $this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->resize())
        {
            $this->image_lib->clear();
            return $this->image_lib->display_errors();
        }
        else
        {
            
            $this->image_lib->clear();
            $this->gallery_thumb($album_folder,$image_name);
            return 'ok';
        }
    }


Here you see I call

Code:
$this->gallery_thumb($album_folder,$image_name);

after resizing and clearing library. But the problem is - it does not add the ending _thumb to thumbnail file now.

Thumbnail creation function:

Code:
function gallery_thumb($album_folder,$image_name)
    {
        
    
        $config['image_library'] = 'gd2';
        $config['source_image']    = './uploads/gallery/'.$album_folder.'/'.$image_name;
        $config['new_image'] = './uploads/gallery/'.$album_folder.'/thumbs';
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 75;
        $config['height']    = 50;
        
        
        
        //$this->load->library('image_lib',$config);
        $this->image_lib->initialize($config);
        echo $config['create_thumb'];
        
        
      
        
        if ( ! $this->image_lib->resize())
        {
          ///  $this->image_lib->display_errors();
              log_message('error', $this->image_lib->display_errors());
              //echo $this->image_lib->display_errors();     //test
              $this->image_lib->clear();
            return FALSE;
        }
        else
        {
            $this->image_lib->clear();
            return TRUE;
        }
    }

As you can see there is such line to add _thumb:

$config['create_thumb'] = TRUE;

But it seems that library just ignores it. I don't understand why is that?

Edit:

Found a one thing:

in the library there is such code:
Code:
if ($this->create_thumb === FALSE OR $this->thumb_marker == '')
        {
            $this->thumb_marker = '';
        }

And I checked that $this->thumb_marker has value '' so thats why it does not add the ending. Now the question why it has such value? I didn't set the marker in my gallerry thumb function and I didn't set it anywhere.

After That I just added line

$config['thumb_marker'] = '_thumb';

in gallery_thumb function and then it creates good filename. But how did it dissapier..




Theme © iAndrew 2016 - Forum software by © MyBB