Welcome Guest, Not a member yet? Register   Sign In
image_lib bug?
#1

[eluser]davdtm[/eluser]
Hi everybody, I'm trying to exploit the image_lib tools to rescale twice an image got from an upload. My final goal is rescale the original image (of arbitrary size) once it's available after uploading, to a standard "big" size and a standard "small" (meaning thumbnail) size, getting two final images from one. For this, once got the image from the upload I run resize() a first time passing suitable values for the following parameters:

'source_image'=>'/path...',
'new_image'=>'/path...',
'create_thumb' => TRUE,
'width'=>$width_thumbnail,
'height'=>$height_thumbnail

This generates a new thumbnailed image, as desired. Then I clean up the parameters with:

$this->image_lib->clear()

and I re-run resize() passing:

'source_image'=>'/path...',
'width'=>$width_large_image,
'height'=>$height_large_image

missing the 'create_thumb' and 'new_image' parameters I thought I should have had a rescaling applied to the original image. However I saw it was not true, because $this->image_lib->clear() does not reset 'create_thumb'. In fact, forcing 'create_thumb' to FALSE in this second parameters set, I got the desired result.

First question: do you think this is a bug? I would say yes, I don't see any reason to clean all the variables but 'create_thumb'.

Second question: Don't you think it might be very useful to add another function, say $this->image_lib->reset(), which restores the default values of all variables? Because clear does not restore the defaults, but just sets all the values to empty strings.

Thanks

Davide
#2

[eluser]fesweb[/eluser]
If it's not a bug, it is short-sighted at least. I found the same issue yesterday and wanted to suggest a fix to the development team.

Now I just extended the library; using the constructor to capture the default values to an array, and reset function overwrites the vars with the defaults from that array. It seems to work so far.

Here is what I've got
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
* Add reset function to restore var defaults
*
* @author fesweb -
* @package EYE
* @subpackage Libraries
* @category Libraries
*/
class MY_Image_lib extends CI_Image_lib {

    var $var_defaults = array();
    
    function __construct()
    {
        parent::__construct(); // Extends the image_lib library    
        foreach ($this as $var => $value)
        {
            $this->var_defaults[$var] = $value;
        }
        // echo var_dump($this->var_defaults);
    }
    function reset()
    {
        foreach ($this->var_defaults as $var => $value)
        {
            $this->$var = $value;
        }
        // echo var_dump($this->var_defaults);
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB