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

TypeError with Image::fit() Method in Laravel using HasMediaPreviewsTrait #94

Open
senecolas opened this issue May 24, 2024 · 0 comments
Assignees

Comments

@senecolas
Copy link

senecolas commented May 24, 2024

Description:

I am encountering a TypeError when attempting to upload images with HasMediaPreviewsTrait.
This seems to be related to recent updates either in the PHP version or the Spatie library that enforce stricter type checks.

Error Message:

Spatie\Image\Image::fit(): Argument #1 ($fit) must be of type Spatie\Image\Enums\Fit, string given, called in /vendor/spatie/laravel-medialibrary/src/Conversions/Manipulations.php on line 55

Environment:

  • Craftable Pro version: 2.0.2
  • Laravel version: 10.48
  • PHP version: 8.3.2

Suggested Fix:

The issue arises due to a type mismatch in the fit() method within the autoRegisterPreviews function of the HasMediaPreviewsTrait. The function needs to be updated to use the enum type instead of a string to specify the fit method. Here is the proposed change:

public function autoRegisterPreviews($size = 200): void
{
    $this->addMediaConversion('preview')
        ->width($size)
-        ->fit('crop', $size, $size) 
+        ->fit(Fit::Crop, $size, $size) 
        ->optimize()
        ->nonQueued()
        ->performOnCollections(...$this->getRegisteredMediaCollections()->map->getName()->toArray());
}

Thank you for considering this change. It would be helpful to check for similar issues to ensure consistent compatibility with the latest library standards.

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

No branches or pull requests

2 participants