milesj / uploader

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

Apply transformations with nameCallback will fail if trying to transform to lower resolution twice #140

Closed danielskapunk closed 11 years ago

danielskapunk commented 11 years ago

Here is how to reproduce In the model I have:

public $actsAs = array(
        'Uploader.Attachment' => array(
            'url' => array(
                //'nameCallback' => 'formatName',
                'overwrite' => false,
                'allowEmpty' => false,
                'transforms' => array(
                    'urlThumbnail' => array(
                        'nameCallback' => 'thumbnailImageNameCallback',
                        'method' => 'resize',
                        'width' => 46,
                    ),
                    'urlSmall' => array(
                        'nameCallback' => 'smallImageNameCallback',
                        'method' => 'resize', // or crop
                        'width' => 205,
                    ),
                    'urlMedium' => array(
                        'nameCallback' => 'mediumImageNameCallback',
                        'method' => 'resize',
                        'width' => 295,
                    ),
                    'urlLarge' => array(
                        'nameCallback' => 'largeImageNameCallback',
                        'method' => 'resize',
                        'width' => 365,
                        //'self'    => true
                    ),
                )
            ),
        )
    );
public function thumbnailImageNameCallback($name, $file){
    $new_name = $this->getUploadedFile()->name();
    $new_name = $new_name . '_thumbnail';
    return $new_name;
}
public function smallImageNameCallback($name, $file){
    $new_name = $this->getUploadedFile()->name();
    $new_name = $new_name . '_small';
    return $new_name;
}

public function mediumImageNameCallback($name, $file){
    $new_name = $this->getUploadedFile()->name();
    $new_name = $new_name . '_medium';
    return $new_name;
}
public function largeImageNameCallback($name, $file){
    $new_name = $this->getUploadedFile()->name();
    $new_name = $new_name . '_large';
    return $new_name;
}

And It works with an image size of 450x600 But fails with an image size of 180x180

Here is the error message I get from validationErrors

(int) 0 => 'rename(SOMEPTAH/test_image1-1-resize-181x181.jpg,SOMEPTAH/test_image1-1_medium.jpg): The system cannot find the file specified. (code: 2)'

Workaround: I added

expand => true

to every transformation, that way original doesn't overwrites itself

milesj commented 11 years ago

Fixed it in Transit, update to 1.4.4.