milesj / uploader

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

Large tall images are saving rotated 90º #143

Closed robksawyer closed 11 years ago

robksawyer commented 11 years ago

Images uploaded via iPhone are rotated automatically. Any idea how to fix this?

I found the following StackOverflow post (http://stackoverflow.com/questions/13971491/captured-photo-automatically-rotated-during-upload-in-ios-6-0-or-iphone), but I'm just curious if you've run across this.

milesj commented 11 years ago

Never ran into it myself, but the ExifTransformer will auto-rotate and fix orientation based on exif data.

robksawyer commented 11 years ago

Should I accept more exif data like 'orientation' via the metaColumns array in setup?

Like this?

'metaColumns' => array(
                    'name' => 'name',
                    'ext' => 'extension',
                    'type' => 'mimeType',
                    'size' => 'fileSize',
                    'width' => 'width',
                    'height' => 'height',
                    'orientation' => 'orientation'
                ),
milesj commented 11 years ago

Using the transformer is similar to the others: http://milesj.me/code/cakephp/uploader#transforming-images-resize-crop-etc There is also exif specific meta data: http://milesj.me/code/cakephp/uploader#saving-meta-data

robksawyer commented 11 years ago

To confirm, like so?

public $actsAs = array(
        'Containable',
        'Uploader.FileValidation' => array(
            'fileName'  => array(
                'type' => array('image'), //The type value can be anything before the / in the mime type declarations.
                'required' => false,
                'minWidth'  => 150,
                'minHeight' => 150,
                'filesize' => 10485760 //10 MB
            )
        ),
        'Uploader.Attachment' => array(
            'fileName' => array(
                'nameCallback' => 'formatFileName',
                'overwrite' => false,
                'stopSave' => false,
                'required' => false,
                'dbColumn' => 'path',
                'uploadDir' => '/tmp',
                'finalPath' => '/',
                'metaColumns' => array(
                    'name' => 'name',
                    'ext' => 'extension',
                    'type' => 'mimeType',
                    'size' => 'fileSize',
                    'width' => 'width',
                    'height' => 'height'
                ),
                'transforms' => array(
                    'path' => array(
                        'method' => 'exif',
                        'self' => true
                    ),
                    'path_small' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'resize',
                        'overwrite' => true,
                        'width' => 75
                    ),
                    'path_small_crop' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'crop',
                        'append' => '_crop',
                        'overwrite' => true,
                        'width' => 75,
                        'height' => 75
                    ),
                    'path_med' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'resize',
                        'overwrite' => true,
                        'width' => 250
                    ),
                    'path_med_crop' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'crop',
                        'append' => '_crop',
                        'overwrite' => true,
                        'height' => 250,
                        'width' => 250
                    ),
                    'path_large' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'resize',
                        'expand' => true,
                        'overwrite' => true,
                        'width' => 640
                    ),
                    'path_large_crop' => array(
                        'nameCallback' => 'transformName',
                        'method' => 'crop',
                        'append' => '_crop',
                        'expand' => true,
                        'overwrite' => true,
                        'height' => 640,
                        'width' => 640
                    )
                ),
                'transport' => array(
                    'class' => AttachmentBehavior::S3,
                    'accessKey' => CC_S3_ACCESS_KEY,
                    'secretKey' => CC_S3_SECRET_KEY,
                    'bucket' => '',
                    'region' => Aws\Common\Enum\Region::US_WEST_2,
                    'folder' => '',
                    'meta' => array(
                        'ext' => 'extension',
                        'type' => 'mimeType',
                        'size' => 'fileSize',
                        'width' => 'width',
                        'height' => 'height'
                    )
                )
            )
        )
    );
robksawyer commented 11 years ago

I'm getting the following when uploading locally.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9792 bytes) in /Users/robksawyer/Sites/com/curdcollective/app/Vendor/mjohnson/transit/src/Transit/Transformer/Image/RotateTransformer.php on line 56

Note: The image is pretty large. It's 1.8mb and 2448x3264. I'm just testing with the worst possible scenario that someone might upload.

milesj commented 11 years ago

With all those transforms and stuff going on, PHP can't handle that large of a file. You can try messing with ini settings and removing the memory/time limit.

robksawyer commented 11 years ago

Yeah, I figured that was the issue. I may just offload these transforms to one of the good ol' Heroku addons. That is, after I run exif.

robksawyer commented 11 years ago

Is there anyway to keep exif data during the resize like the following? It seems as if it gets removed during the resize, right?

array(
    'nameCallback' => 'transformName',
    'method' => 'resize',
    'width' => 1280,
    'overwrite' => true,
    'self' => true
),
array(
    'method' => 'exif',
    'self' => true
),
milesj commented 11 years ago

Modifying images automatically removes exif data, that's just how it works, nothing I'm doing.

robksawyer commented 11 years ago

Got it. Thanks.