milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

How to resize uploaded image by not creating new ones #103

Closed p4004 closed 11 years ago

p4004 commented 11 years ago

My code looks like this:

  public $actsAs = array(  
    'Uploader.Attachment' => array(
        'upload' => array(
            'baseDir'   => '',
            'uploadDir' => '',
            'dbColumn'  => 'path',
            'importFrom'    => '',
            'defaultPath'   => '',
            'maxNameLength' => 30,
            'overwrite' => false,
            'stopSave'  => true,
            'allowEmpty'    => false,
            'transforms' => array(
                array('method' => 'crop', 'width'=>754, 'height'=>510, 'append'=> false, 'uploadDir' => '/files/uploads/medium/', 'dbColumn' => 'path_medium'),
                array('method' => 'resize', 'width'=>377, /*'height'=>280,*/ 'append'=> false, 'uploadDir' => '/files/uploads/medium_small/', 'dbColumn' => 'path_medium_small'),
                array('method' => 'crop', 'width'=>234, 'height'=>158, 'append'=> false, 'uploadDir' => '/files/uploads/thumb/', 'dbColumn' => 'path_thumb'),
                array('method' => 'crop', 'width'=>130, 'height'=>85, 'append'=> false, 'uploadDir' => '/files/uploads/thumb_small/', 'dbColumn' => 'path_thumb_small'),

                // I AM TRYING TO RESIZE ORIGINAL IMAGE WITH THIS LINE
                array('method' => 'resize','self' => true, 'width'=>1600, 'height'=>1200, 'append'=> false, 'uploadDir' => '/files/uploads/', 'dbColumn' => 'path', 'overwrite' => true),
            ),
            'metaColumns' => array( 
                'ext' => 'ext',
                'type' => 'type',
                'size' => 'size',
                'group' => '',
                'width' => 'width',
                'height' => 'height',
            )
        ),
    ),
);

In transformations array I have this last line:

array('method' => 'resize','self' => true, 'width'=>1600, 'height'=>1200, 'append'=> false, 'uploadDir' => '/files/uploads/', 'dbColumn' => 'path', 'overwrite' => true),

It resizes original image and overwrites the original, but it seems to be a little buggy. The new image size is not saved to database, and not all transformations before this one are being completed.

I tried other combinations like removing 'self' => true, or 'overwrite' => true, but that gave even worse results.

In plugins documentation it is written: "Transform the uploaded image or create new images:". So how could I transform the very uploaded image without creating new one? :) I could not find that explained in documentation.

Many thanks

milesj commented 11 years ago

What version are you using? Self transformation is only available for v4+ using self = true. Applying the same dbColumn just saves the new path but I don't remember if it actually overwrites the original.

By the settings you are using, I'm assuming this is a v3 setup.

p4004 commented 11 years ago

Yes, I am using v3. Ok, I'll need to upgrade or find a way around. Thanks anyway.

One suggestion would be that you leave documentation for previous versions of plugin, so f.e. example if we need to modify our running projects which use older version of plugin, we could find documentation for that.

F.e. I have made one project where Upload process is held in controller, but now I don't find information at your website how this is controlled, as v4 seems to be created for use only by attaching behavior through model.

milesj commented 11 years ago

Yeah, I hear that a lot. My site doesn't support docs for multiple versions so it will always display docs for the latest version. I have no time to build support for other versions, nor do I have time to actually write the docs. Sorry.