Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flyingL123 opened this issue Jan 7, 2019 · 7 comments
Labels

Comments

@flyingL123
Copy link

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
Copy link
Author

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.

@czim czim added the bug label Jan 7, 2019
@czim
Copy link
Owner

czim commented Apr 28, 2019

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 czim added usage help and removed bug labels Apr 28, 2019
@czim czim closed this as completed Apr 28, 2019
@kimchirichie
Copy link

kimchirichie commented Oct 15, 2020

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!

@czim
Copy link
Owner

czim commented Oct 17, 2020

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 czim reopened this Oct 17, 2020
@kimchirichie
Copy link

kimchirichie commented Oct 20, 2020

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
Copy link

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.

@czim czim added bug and removed usage help labels Oct 20, 2020
@czim
Copy link
Owner

czim commented Oct 20, 2020

file-handling 2.0.3 should fix the issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants