Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Image manipulation on upload
  • It would be nice to have option to tell Image class file extension on load. Such behavior would be useful on uploaded images, when they don't have extension.
    For now we have to:
    1. rename uploaded file to something with original extension
    2. load it to image class and save it to needed file name and extension
    3. delete previously moved file But if we could do something like \Image::load('tmp_name', false, 'jpeg');
    Then we would need to only load file and save it with needed file name and extension. Or did I missed something?!
  • If it is only about extension, why not simply rename the file? See http://docs.fuelphp.com/classes/file/usage.html#/method_rename.
  • This is the first step - rename uploaded file ( which uploaded without extension ) to the file name with original extension. But if I want to resize image and save file as {md5_chksum}.jpeg, i have to save image and then again rename file or save it in needed format and then remove original. To much action needed.. P.S. Image_Driver::load() method support second argument $return_data, but Image::load expects exactly one argument.. Hmm.
    P.S.S. With minor tweaks to Image::load() logic I've added third param to force load images without extension and check extension on compatibility by that third argument. So now I only need to do something like that:
    $file_info = \File::file_info($file['tmp_name']);
    list($file_myme, $file_ext) = explode('/', $file_info['mimetype']);
    
    \Image::load($file['tmp_name'], false, $file_ext)
                                ->resize(600, 600, true)
                                ->watermark(DOCROOT.'assets'.DS.'img'.DS.'watermark.jpg', 'bottom right')
                                ->save($new_path, 0755)
                                ->resize(120, 120, true)
                                ->save($new_path_thumb, 0755);
    
  • You get the name and the mimetype from the Upload class, so you can use that to rename. I still believe it's not the task of the Upload class to deal with this, I might want files without extensions in my application, and the feature you're proposing will not allow that anymore.
  • Thank you for Upload class I'll check that.
    I still believe it's not the task of the Upload class to deal with this, I might want files without extensions in my application, and the feature you're proposing will not allow that anymore.

    Hmm, I only proposed to allow Image class receive third parameter which will tell Image class what extension loaded image is, in case image file doesn't have any.. for example: /tmp/phpEx6cfd Upload class is not touched at all...
  • Add a feature request at http://github.com/fuel/core/issues, and see if someone is willing to pick it up. Otherwise, fork the repo, make the changes yourself, and send a pull request.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion