Skip to content

Add Image Upload/Attachment Optimization#691

Open
Matarim wants to merge 3 commits intobasecamp:mainfrom
Matarim:add-image-upload-optimization
Open

Add Image Upload/Attachment Optimization#691
Matarim wants to merge 3 commits intobasecamp:mainfrom
Matarim:add-image-upload-optimization

Conversation

@Matarim
Copy link

@Matarim Matarim commented Jan 26, 2026

I brought this idea here: Idea Discussion, but the goal of this work is to provide the ability to optimize images that are attached to Lexxy form.

Can this work be done elsewhere:
This work can be done in an initializer in your project that patches the ActiveStorage::Attachment to pull down the attached images loop through and modify the storage object and the blob. This requires modifying the HTML to point to the new key after conversion and honestly would not be optimal for heavy usage, but is possible.

Why I think it belongs here:
Doing the work at the time of the preview front-loads the optimization process and gives an easier way to handle modifying the optimization based on where it is being used by simply changing the configuration.

I'm attaching an example of how to use below, but that is also available in the discussion brought up before.

import * as Lexxy from "lexxy"

Lexxy.configure({
    global: {
        imageOptimization: {
            enabled: true,
            format: "webp",
            maxWidth: 1200,
            maxHeight: 900,
            quality: 0.8
        },
    }
})

Additional consideration and thoughts on restricting optimization on certain file types like svg may be a good plan here, and I'm open to discussion and ideas on how to better handle image file types that shouldn't be converted to a different format/quality.

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

Comments