1
for($i=0;$i<count($status);$i++)
{
    $conf = array(
        'source_image' => $status[$i]['full_path'],
        'new_image' => $this->upload_path . '/thumbs',
        'maintain_ratio' => true,
        'width' => 200,
        'height' => 200
    );

    $this->load->library('image_lib', $conf);
    $this->image_lib->resize();

    $this->image_lib->clear(); // complete reset    
    $this->image_lib->initialize($conf); // complete reset
}

            .

always keep missing the last thumbnail creation cycle. when trying for($i=0;$i<=count($status);$i++). i get this notice Undefined offset

4
  • when i keep the condition as less than $status i miss an image, when i keep the condition as less than equal to the script creates a blank array. Commented Mar 29, 2012 at 13:44
  • Can you post the var_dump of the array, please? Commented Mar 29, 2012 at 13:45
  • Are you sure that the full_path index exists in the last item of the $status? Commented Mar 29, 2012 at 13:47
  • 1
    Pretty please (with sugar on top) don't use count() in a loop condition. Cache the array length in a variable before the loop. Commented Mar 29, 2012 at 13:49

2 Answers 2

2

By using a for loop you are assuming that the keys of the array are contiguous, which they may not be. You are also assuming that every second level array has a full_path key, which it may not. Use foreach instead, and do an isset() check on the full_path key:

foreach ($status as $item)
{

    if (!isset($item['full_path'])) continue;

    $conf = array(
        'source_image' => $item['full_path'],
        'new_image' => $this->upload_path . '/thumbs',
        'maintain_ratio' => true,
        'width' => 200,
        'height' => 200
    );

    $this->load->library('image_lib', $conf);
    $this->image_lib->resize();

    $this->image_lib->clear(); // complete reset    
    $this->image_lib->initialize($conf); // complete reset
}
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

$this->load->library('image_lib');
$stat = array_values($status);
for($i=0;$i<count($stat);$i++)
{
$conf = array(
    'source_image' => $stat[$i]['full_path'],
    'new_image' => $this->upload_path . '/thumbs',
    'maintain_ratio' => true,
    'width' => 200,
    'height' => 200
);

$this->image_lib->initialize($conf); // complete reset
$this->image_lib->resize();

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.