© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago
Ralph Morris

Uploading file and setting max width/auto height

Hey all, hoping someone can help.
I have the following code:
Forms\Components\FileUpload::make('image')
    ->directory('cms')
    ->image()
    ->imageEditor()
    ->imageEditorAspectRatios([
        null,
        '16:9',
        '9:16',
        '4:3',
        '3:4',
        '1:1',
    ])
    ->imageResizeMode('contain')
    ->imageResizeTargetWidth('1288')
Forms\Components\FileUpload::make('image')
    ->directory('cms')
    ->image()
    ->imageEditor()
    ->imageEditorAspectRatios([
        null,
        '16:9',
        '9:16',
        '4:3',
        '3:4',
        '1:1',
    ])
    ->imageResizeMode('contain')
    ->imageResizeTargetWidth('1288')

I am trying to upload an image and reduce and images that are too large to max 1288px width, whilst keeping the height dynamic. However, the above code stretches a smaller image to hit 1288px width.

How can i stop it stretching the image and only reduce the size if too big?

Thanks
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Uploading image save width and height
FilamentFFilament / ❓┊help
3y ago
Image min and max width and height
FilamentFFilament / ❓┊help
3y ago
Fixing height and width of fileupload in the context of Video Uploading
FilamentFFilament / ❓┊help
10mo ago
richeditor max height
FilamentFFilament / ❓┊help
3y ago