Welcome Guest, Not a member yet? Register   Sign In
Image library & foreach
#1

[eluser]NetStranger[/eluser]
i need to make thumbs for lots of images in the folder once... and i right this code :
Code:
$data = directory_map('./img/photo/'.$page);
             foreach ($data as $val => $img) // images in photo
                        {
                               if (!is_array($img))  // if it is not array
                                {
                                $must_thumb = '';
                                        foreach ($data['thumbs'] as $val2 => $img2) // path to thumb
                                             {
                                                  if (substr($img2, 0, -10) == substr($img, 0, -4))
                                                  {
                                                       $must_thumb = '/img/photo/'.$page.'/thumbs/'.$img2;
                                                  }
                                             }
                                $thumb = '/img/photo/'.$page.'/thumbs/'.substr($img, 0, -4)."-thumb".substr($img, -4); // thumb
                                echo '<h1>'.$must_thumb.'='.$thumb.'</h1>';
                                        
                                        if ($must_thumb != $thumb) // if there is no thumb realy
                                        { // make thumb
                                            echo "<h2>".$check."</h2>";
                                            $check = ++$check;

                                            $config['image_library'] = 'gd2';
                                            $config['source_image'] = './img/photo/'.$page.'/'.$img;
                                            $config['create_thumb'] = TRUE;
                                            $config['maintain_ratio'] = TRUE;
                                            $config['width'] = 150;
                                            $config['height'] = 100;
                                            $config['thumb_marker'] = "-thumb";
                                            $config['new_image'] = './img/photo/'.$page.'/thumbs/'.$img;

                                            
                                            $this->load->library('image_lib', $config);
                                          
                                            if ( ! $this->image_lib->resize())
                                            {
                                                echo $this->image_lib->display_errors();
                                            }
                                            
                                          

                                            echo "<img src='".$thumb."' />";
                                            echo '<br />';
                                        }
                                        else
                                        {
                                            echo "<img src='".$thumb."' />";
                                            echo '<br />';
                                        }


                                }

                        }

but it's not work correctly. when i load page, thumb makes for first picture ONLY! other pictures dont create thumb . Then i do refresh of the page and NEXT picture get its thumb BUT third - not... etc .Why ? where my mistake?? thanks
#2

[eluser]Pascal Kriete[/eluser]
The image library (and all other CI libraries), are only instantiated once. So calling the loader again will not change the config settings. Instead you'll want to use the initialize() and clear() functions:
Code:
$this->load->library('image_lib');

foreach($images as $path => $image)
{
    $config['...'] = '....';
    $this->image_lib->initialize($config);

    // Processing goes here

    $this->image_lib->clear();
}
#3

[eluser]NetStranger[/eluser]
thanx very much!!!
#4

[eluser]Thorpe Obazee[/eluser]
And the subsequent call to load the image library is also ignored.




Theme © iAndrew 2016 - Forum software by © MyBB