Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED] Resizing images and making thumbnails in a loop...
#1

[eluser]digitalbloke[/eluser]
This post has been resolved. Please see post 3 below

Hi guys.

Hope someone can help me, this has been driving me mental!

I have a loop that is trying to resize an uploaded image and then create a thumbnail from the resized image. The thumbnail code work for all three image, but the resize code only works for the first image. If I run the resize code without the thumbnail code it works fine...

I'm loading the image library outside of the loop, running the initialize() function in the loop and running the clear() function after each resize. I'm also unsetting the config array!

If anyone could help me out that would be great, I think I've been looking at this code too long!

Thanks in advance!
Code:
<?php

class Image extends Controller
{    
    function index()
    {
        $this->load->library('image_lib');
        
        $images = array('1.jpg', '2.jpg', '3.jpg');
        
        foreach ($images as $item)
        {
            // resize large image
            $config_large['source_image'] = './uploads/' . $item;
            $config_large['maintain_ratio'] = true;
            $config_large['width'] = 640;
            $config_large['height'] = 480;
            $config_large['quality'] = 100;
            
            $this->image_lib->initialize($config_large);
            
            if ( ! $this->image_lib->resize())
            {
                echo $this->image_lib->display_errors();
            }
            
            $this->image_lib->clear();
            unset($config_large);
            
            // create thumbnail
            $config_thumb['source_image'] = './uploads/' . $item;
            $config_thumb['maintain_ratio'] = true;
            $config_thumb['width'] = 199;
            $config_thumb['height'] = 150;
            $config_thumb['quality'] = 60;
            $config_thumb['create_thumb'] = true;
            $config_thumb['thumb_marker'] = '_t';
            
            $this->image_lib->initialize($config_thumb);
            
            if ( ! $this->image_lib->resize())
            {
                echo $this->image_lib->display_errors();
            }
            
            $this->image_lib->clear();
            unset($config_thumb);
        }
    }
}
#2

[eluser]Sean Gates[/eluser]
I know it's overkill, but have you tried putting the
Code:
$this->load->library('image_lib');
inside the loop?
#3

[eluser]digitalbloke[/eluser]
Hi Sean

Thanks for replying. I tried that and sadly no joy Sad
#4

[eluser]cahva[/eluser]
Congratulations, you have found a bug! Smile

I did a little digging and this is a bug in the clear() method. It didnt clear "thumb_marker" so actually it did resize it but it resized it to the thumb name and after that the thumb creator overwrites it again as thumb_marker is added to "full_dst_path" when defining it. Thats why only the first one worked.

To fix the problem, add "thumb_marker" to the clear() method found in system/libries/Image_lib.php on line 108.

It should look like this:
Code:
$props = array('thumb_marker','source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');

I'll post this bug to devs.
#5

[eluser]cahva[/eluser]
Made a bugreport:
http://codeigniter.com/bug_tracker/bug/11137/
#6

[eluser]digitalbloke[/eluser]
[quote author="cahva" date="1263885187"]Congratulations, you have found a bug! Smile[/quote]
Cool, do I get a prize?

Thanks for taking the time to look into this form me. It is very much appreciated, it was driving me crazy and I really need it for a few projects Smile

I guess this is the benefit of open source software and a thriving user community Smile
#7

[eluser]federico_jacobi[/eluser]
@cahva Sorry to bring this issue up again, but even after doing the fix, the problem remains ... UNLESS ... you explicitly set 'thumb_maker' to something like '_thumb', which should actually be the default.

In other words, clear() should bring everything to default values I.M.H.O. Not quite a bug, but an odd behavior.
#8

[eluser]kobeddon[/eluser]
now this saved my life...whew
#9

[eluser]novarli[/eluser]
[quote author="cahva" date="1263867187"]Congratulations, you have found a bug! Smile

I did a little digging and this is a bug in the clear() method. It didnt clear "thumb_marker" so actually it did resize it but it resized it to the thumb name and after that the thumb creator overwrites it again as thumb_marker is added to "full_dst_path" when defining it. Thats why only the first one worked.

To fix the problem, add "thumb_marker" to the clear() method found in system/libries/Image_lib.php on line 108.

It should look like this:
Code:
$props = array('thumb_marker','source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');

I'll post this bug to devs.[/quote]

Wow excellent ...




Theme © iAndrew 2016 - Forum software by © MyBB