Skip to content

Conversation

dive-michiel
Copy link

Hi,

We have a use case where we would like to customize conversions based on custom attributes. To get this working the custom fields need to be saved when the model is created (since the conversions triggers as soon as the model is created).

Here is an example of what we are trying to achieve, but could be any image manipulation based on a custom field:

Images::make('Slideshow', 'slideshow')
    ...
    ->customPropertiesFields([
        Select::make('Crop', 'crop')->options([
            Manipulations::CROP_LEFT => 'Left',
            Manipulations::CROP_CENTER => 'Center',
            Manipulations::CROP_RIGHT => 'Right',
        ])->default(Manipulations::CROP_CENTER),
    ])
    ...
public function registerMediaConversions(Media $media = null): void
{
    $crop = $media->getCustomProperty('crop') ?? Manipulations::CROP_CENTER;

    ...

    $this->addMediaConversion('thumb-two-thirds')
            ->performOnCollections('thumb')
            ->withResponsiveImages()
            ->crop($crop, 580, 870);

    ...

This pull request fixes that problem, if we need to improve or change the code let us know!

✨ Save custom fields on model creation
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

Successfully merging this pull request may close these issues.

1 participant