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

Image load fix #214

Merged
merged 2 commits into from
Dec 18, 2023
Merged

Image load fix #214

merged 2 commits into from
Dec 18, 2023

Conversation

kbond
Copy link
Contributor

@kbond kbond commented Dec 18, 2023

Reference: https://twitter.com/freekmurze/status/1736801633986916639

When passing an image filename to Image::__construct() and Image::load(), the file wasn't actually being loaded by the driver. The only way for it to work would be (new Image())->loadFile('file/path').

@@ -28,6 +28,10 @@ class Image implements ImageDriver
public function __construct(protected ?string $pathToImage = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a property on the Image object? It isn't actually used anywhere but it is protected so I guess removing is a BC break.

If we keep, Image::loadFile() should probably set this property as well?

it('it can load image from file', function () {
$image = Image::load(getTestJpg());

expect($image->getHeight())->toEqual(280);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this fix, this test (getHeight()) produces the following error:

Typed property Spatie\Image\Drivers\Imagick\ImagickDriver::$image must not be accessed before initialization

@freekmurze
Copy link
Member

That's indeed an oversight from our end. Thank you for this fix!

@freekmurze freekmurze merged commit 83ebc84 into spatie:main Dec 18, 2023
3 checks passed
@kbond kbond deleted the image-load-fix branch December 18, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants