laravel-paperclip icon indicating copy to clipboard operation
laravel-paperclip copied to clipboard

InvalidArgumentException with message 'Height value for portrait resize is empty. This may be caused by unfixed EXIF-rotated images'

Open flyingL123 opened this issue 5 years ago • 7 comments

I'm receiving the following error trying to save a photo with variants:

InvalidArgumentException with message 'Height value for portrait resize is empty. This may be caused by unfixed EXIF-rotated images'

This is my model set up:

$this->hasAttachedFile('image', [
	'variants' => [
			Variant::make('thumbnail')->steps([
					AutoOrientStep::make(),
					ResizeStep::make()->width(300),
			]),

			Variant::make('zoom')->steps([
					AutoOrientStep::make(),
					ResizeStep::make()->width(1280)->convertOptions(['quality' => 100]),
			]),
	],
]);

This is the image I am trying to save with variants when I receive the error:

https://s3.amazonaws.com/storeyourboard/App/CustomerPhoto/000/000/014/image/original/image_82432486101421854469.jpg

I have no clue what this error means. Can you explain?

flyingL123 avatar Jan 07 '19 05:01 flyingL123

Additionally, when I use the old variant syntax, it works fine:

$this->hasAttachedFile('image', [
	'variants' => [
		'thumbnail' => [
			'auto-orient' => [],
			'resize' => ['dimensions' => '300', 'convert_options' => ['quality' => 100]],
		],
		'zoom' => [
			'auto-orient' => [],
			'resize' => ['dimensions' => '1280'],
		],
	],
]);

I do not receive the error when I set it up this way.

flyingL123 avatar Jan 07 '19 05:01 flyingL123

First off, I'm not sure that dimensions 300 is syntactically the same as setting ->width(300). Isn't dimensions 300 the same as 300x300? This is besides the point for this particular error, but it may be relevant to your use case. If so, try using ->square(300) instead.

As for the error, this is due to the auto-orient step being applied after the resize step. This is what the error message alludes to, by the way.

You can fix this by changing your config to:

			Variant::make('thumbnail')->steps([
					ResizeStep::make()->width(300),
					AutoOrientStep::make(),
			]),

			Variant::make('zoom')->steps([
					ResizeStep::make()->width(1280)->convertOptions(['quality' => 100]),
					AutoOrientStep::make(),
			]),

czim avatar Apr 28 '19 10:04 czim

having an issue too. (without AutoOrientStep)

        $this->hasAttachedFile('image', [
            'variants'  => [
                Variant::make('thumb')->steps([
                    ResizeStep::make()->width(480)->height(270)->crop(), // = '480x270#'
                ]),
                Variant::make('small')->steps([
                    ResizeStep::make()->width(480), // = '480x'
                ]),
                Variant::make('medium')->steps([
                    ResizeStep::make()->width(640), // = '640x'
                ]),
                Variant::make('large')->steps([
                    ResizeStep::make()->width(1280), // = '1280x'
                ]),
            ],
            'url' => config('services.cdn.image_not_found'),
        ]);

thumb works, but others are not working.

Logging from Czim\Paperclip\Attachment\Attachment.php; L#789 gives:

[2020-10-15 04:31:37] local.DEBUG: InvalidArgumentException: Height value for portrait resize is empty. This may be caused by unfixed EXIF-rotated images in /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Support/Image/Resizer.php:219

seems to be an issue with the height being a variable? the lack of documentation really hinders me from being able to resolve this on my own. reaching for help!

kimchirichie avatar Oct 15 '20 04:10 kimchirichie

I've found and corrected an issue with the file-handling package. It turned out that ->width(<something>) was internally rendered as dimensions string <something>x (with the x included), which was incorrectly interpreted by the resize logic as matching the 'portrait' resize approach (when it should be 'landscape', since it's width-based.

This has been fixed in czim/file-handling version 2.0.2. If you're using the newest version of paperclip, you should be able to composer update it. Please let me know if this resolves your issue.

czim avatar Oct 17 '20 12:10 czim

amazing. thanks for reopening this! this issues been on my mind all of last week. just got to try it out and got a different error this time!

Here is the stack trace:

[2020-10-20 06:08:38] local.DEBUG: ErrorException: A non well formed numeric value encountered in /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Support/Image/Resizer.php:304
Stack trace:
#0 /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Support/Image/Resizer.php(304): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'A non well form...', '/Users/brainfog...', 304, Array)
#1 /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Support/Image/Resizer.php(197): Czim\FileHandling\Support\Image\Resizer->getSizeByFixedWidth(Object(Imagine\Gd\Image), '480x')
#2 /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Support/Image/Resizer.php(60): Czim\FileHandling\Support\Image\Resizer->resizeLandscape(Object(Imagine\Gd\Image), '480x', NULL)
#3 /Users/brainfogz/Documents/GitHub/oap/vendor/czim/file-handling/src/Variant/Strategies/ImageResizeStrategy.php(34): Czim\FileHandling\Support\Image\Resizer->resize(Object(SplFileInfo), Array)
....

It seems like 480x is a non well formed numeric value. i will dig thru file-handling and see if i can find anything.

kimchirichie avatar Oct 20 '20 06:10 kimchirichie

upon inspection, the Resizer::parseOptionDimensions had returned 480x instead of 480. I've made a PR and that seems to fix the issue on my end.

This issue is irrelevant to czim/laravel-paperclip and more pertinent to czim/file-handling. should close this issue.

kimchirichie avatar Oct 20 '20 06:10 kimchirichie

file-handling 2.0.3 should fix the issue now.

czim avatar Oct 20 '20 07:10 czim