• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
image_lib bug?

I am trying to solve this problem all night but no luck:

//database connection, pulling the picture from the database
foreach ($query->result() as $row)
    $this->data['sid']       = $row->sid;
    $this->data['aid']       = $row->aid;
    $this->data['filename']  = $row->filename;
    $this->data['filetype']  = $row->filetype;
    $this->data['filesize']  = $row->filesize;
    $this->data['picture']     = $row->picture;

//temp file
$tmpfname  = tempnam("/tmp", "test_");

//putting the picture into a temp file
write_file($tmpfname, $this->data['picture']);

//resize config:
$config['source_image']   = $tmpfname;
$config['new_image']      = '/tmp/test';
$config['maintain_ratio'] = TRUE;
$config['dynamic_output'] = FALSE;
$config['width']          = 120;
$config['height']         = 120;

echo $this->image_lib->display_errors();

If i use dynamic output it works but i don't know what is wrong with new_image config option.

1. If $config['new_image'] = '/tmp/test'; file is not created inside tmp dir, i can't find the file
2. If $config['new_image'] = 'test'; file is created inside tmp dir, i think because the original file is in tmp dir (RTFM says so), but the file name begins with a dot and it is called .test
3. If no new_image is used new file is created, same name as the original, but with a dot: /tmp/.original_file_name, in my case $tmpfname

Is this a bug or a feature? Because the problem can be solved by moving ".original_file_name" to "original_file_name". But if it is a bug i can't take that additional step...

system: centos 5
php: 5.1.6
gd: 2.0.28 bundled (installed from yum repository)


if, for example, we have something like this:
$config['new_image'] = '/tmp/test';

Then CI will see this as a path, not as a file name, and it will create file inside /tmp/test/, the name will begin with a dot.
Even something like this:
$config['new_image'] = '/tmp/test.raw';

will not work, because CI, as far as i can see, expects valid graphic extension (jpg, gif, png etc.)

I don't like this, i don't know about you...

That is an error that kept me up all night. Same error was stopping me from resizing original image without making a copy of that file.

Look at my previous post. i was using tempnam to generate unique file inside tmp dir. tempnam doesn't allow to add extension to file name. Because file name didn't have an extension CI was using tmpfname as a directory, and created file at the wrong location.

I think this is a bug....

Correct, your temporary file never had an extension so it incorrectly misaligned the filename for the extension. This should be fixed.

In the meantime, you can fix it yourself without hacking the core library. Just create a file at /application/libraries/MY_Image_lib.php with a "MY_Image_lib" class inside of it that extends from "CI_Image_lib". Fix the explode_name() function to correctly compute the filename and the file extension. That replacement function will override the one in the core Image_lib library and you'll get the behavior you want.

Thank you.

I rewrote my function so that it generates proper extension based on file type that will be processed (i get this data from file that is already in my database).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.