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

Error when using withManipulations in combination with enumerations #3582

Closed
tkempf opened this issue Apr 11, 2024 · 2 comments
Closed

Error when using withManipulations in combination with enumerations #3582

tkempf opened this issue Apr 11, 2024 · 2 comments
Assignees

Comments

@tkempf
Copy link
Contributor

tkempf commented Apr 11, 2024

When adding media with medialibrary v11 using withManipulations, the BackedEnum BorderType gets transformed to its scalar string value before calling the manipulation itself.
This leads to the following type error:
Spatie\Image\Image::border(): Argument #2 ($type) must be of type Spatie\Image\Enums\BorderType, string given

The code used is as follows:
$this->addMedia($params->favicon->file) ->preservingOriginal() ->withManipulations([ 'bgrectangle' => [ 'background' => ['color'=>$favIconbgcolor], 'border' => ['width' => $bordersize,'type' => BorderType::Expand, 'color'=>$bordercolor] ] ]) ->toMediaCollection('favicon');

@freekmurze
Copy link
Member

It's accept a PR that fixes this.

@tkempf
Copy link
Contributor Author

tkempf commented Apr 15, 2024

Ok, the problem occurs on FileAdder.php line 331 during
$media->manipulations = $this->manipulations;the manipulation get cast to an array as requested in Models/Media.php on Line 74

    protected $casts = [
        'manipulations' => 'array',
        'custom_properties' => 'array',
        'generated_conversions' => 'array',
        'responsive_images' => 'array',
    ];

For my purpose i just need a border, so i made it work for me now by recreating the Enum in Conversions/Manipulations 53
I made a PR but this is just a fast and dirty fix and has to be reviewed toroughly by
someone who has a better knwoledge of media-libary or functionality of custom casts in laravel.

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

3 participants