$this->image_lib->resize() ...fails in a loop - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: $this->image_lib->resize() ...fails in a loop (/showthread.php?tid=41912) |
$this->image_lib->resize() ...fails in a loop - El Forum - 05-20-2011 [eluser]potion[/eluser] Three images are uploaded at once, but image_lib->resize succeeds only on first image. I suspect the cause is obvious, but I can't see it. Here's the function in the controller... Code: function update_project() { $this->image_lib->resize() ...fails in a loop - El Forum - 05-20-2011 [eluser]Atharva[/eluser] Load library outside the loop Code: $config['upload_path'] = './images/projects'; Loading library again if already loaded will throw error. $this->image_lib->resize() ...fails in a loop - El Forum - 05-20-2011 [eluser]potion[/eluser] [quote author="Atharva" date="1305932090"] Loading library again if already loaded will throw error.[/quote] I wasn't getting an error. And all three images had always uploaded successfully. It was the image size manipulation that was failing. Here, <i>image_lib</i> is loaded inside the loop because the config parameters change for each image. Nevertheless, I agree that the upload library should be loaded outside the loop, and have done that. But the image sizing problem remains. I suspect that there is some kind of residue between iterations: Code: for ($i = 1; $i <= 3; $i++) : // upload the three pics $this->image_lib->resize() ...fails in a loop - El Forum - 05-20-2011 [eluser]potion[/eluser] SOLVED (Sorry, I'm a CI newbie. RTFM!) Code: /* LOAD THE LIBRARY ONCE -- BEFORE THE LOOP */ $this->image_lib->resize() ...fails in a loop - El Forum - 04-23-2012 [eluser]Unknown[/eluser] It would also be good to note that $this->image_lib->clear() DOES NOT clear all the properties of the image lib object. function clear() { $props = array('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'); foreach ($props as $val) { $this->$val = ''; } // special consideration for master_dim $this->master_dim = 'auto'; } I had an issue with batch processing where the height was getting auto resized based on a 500px width and the proportions were off because the height was not getting cleared since its not included in the clear method. I had to reset the property manually using by writing: $this->image_lib->height = ''; Once I did this and reset the other values not cleared by that method the loop finally worked for me. Let me know if I should submit a bug for this. |