Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
82ee1fb
feat: add smart optimization to image instant optimization
Arukuen Mar 31, 2026
de8cfe0
fix: remove force arg since we now allow same format conversion for s…
Arukuen Apr 6, 2026
a13e346
Merge branch 'develop' into feat/35-image-smart-optimization
Arukuen Apr 7, 2026
c9f9905
fix: speedup smart optimization, add toggle in admin
Arukuen Apr 7, 2026
90b39a5
Merge branch 'develop' into feat/35-image-smart-optimization
Arukuen Apr 7, 2026
eef9cfb
fix: updated admin setting
bfintal Apr 7, 2026
d5413ac
fix: updated label when smart optimized
bfintal Apr 7, 2026
89c1cd7
fix: smart optimization should be false if on free
bfintal Apr 7, 2026
769e1d4
fix: smart optimization is off if free
bfintal Apr 7, 2026
63684ed
fix: add delayed progress for long optimization
Arukuen Apr 8, 2026
0b65bc6
Merge branch 'feat/35-image-smart-optimization' of https://github.com…
Arukuen Apr 8, 2026
975b741
fix: add progress to smart and non-smart
Arukuen Apr 10, 2026
8f87b2d
fix: use the right progress status
Arukuen Apr 10, 2026
4382fd4
chore: updated tested up to 7.0
bfintal Apr 10, 2026
36b5b00
Merge branch 'feat/35-image-smart-optimization' of https://github.com…
bfintal Apr 10, 2026
94a54a2
always close the progress modal even if it errors
bfintal Apr 20, 2026
8284887
added an indeterminate progress bar style
bfintal Apr 20, 2026
5defd2c
fix: change progress delay from 700ms to 1000ms
Arukuen Apr 22, 2026
90f8f3b
Merge branch 'develop' into feat/35-image-smart-optimization
Arukuen May 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/admin/js/media-manager/drop-zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function addDropZoneListenerToMediaManager( targetDocument ) {
const optimizedResults = await Promise.all(
fileConverters.map( async converter => {
try {
const result = await converter.convert()
const result = await converter.optimize()
if ( result.error ) {
// eslint-disable-next-line no-console
console.warn( result.error )
Expand Down
2 changes: 1 addition & 1 deletion src/admin/js/media-manager/select-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function addSelectFilesListenerToFileUploads( targetDocument ) {
const optimizedResults = await Promise.all(
fileConverters.map( async converter => {
try {
const result = await converter.convert()
const result = await converter.optimize()
if ( result.error ) {
// eslint-disable-next-line no-console
console.warn( result.error )
Expand Down
9 changes: 9 additions & 0 deletions src/shared/converters/converter-abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ class Converter {
throw new Error( 'convert() must be implemented by subclass' )
}

/**
* Perform smart optimization.
* If a subclass has not implemented this method, perform regular conversion.
* @return {Promise<{file: File|Blob, metadata?: Object}>} Promise resolving with the converted file and optional metadata.
*/
async optimize() {
return await this.convert()
}

/**
* Cancel the current conversion.
* Subclasses should override this to implement actual cancellation logic.
Expand Down
25 changes: 17 additions & 8 deletions src/shared/converters/image-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ class ImageConverter extends Converter {

// Skip if already the desired format
const formatInfo = supportedFormats.find( f => f.value === formatTo )
if ( ! force && formatInfo && file.type === formatInfo.mimeType ) {
return {
file,
metadata: null,
reason: 'same-format',
}
}
// if ( ! force && formatInfo && file.type === formatInfo.mimeType ) {
// return {
// file,
// metadata: null,
// reason: 'same-format',
// }
// }

// Check if the browser supports the desired output format
const testCanvas = document.createElement( 'canvas' )
Expand Down Expand Up @@ -359,7 +359,16 @@ class ImageConverter extends Converter {
}

async optimize() {
return await applyFiltersAsync( 'cimo.imageConverter.optimize', this )
let result = await applyFiltersAsync( 'cimo.imageConverter.optimize', {
file: this.file,
metadata: null,
reason: 'no-optimizer',
}, this )

if ( result.reason === 'no-optimizer' || ! result.metadata ) {
result = await this.convert()
}
return result
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/shared/converters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ export const getFileConverter = _file => {
}

if ( file.type.startsWith( 'image/' ) ) {
// If the browser doesn't support webp, then we can't convert it.
if ( ! isFormatSupported( 'webp' ) ) {
return new NullConverter( file )
let format = 'webp'

// If webp is not supported, use the same format of the file.
if ( ! isFormatSupported( format ) ) {
format = file.type
}

if ( ImageConverter.supportsMimeType( file.type ) ) {
return new ImageConverter( file, {
format: 'webp',
format,
quality: window.cimoSettings?.webpQuality || 0.8,
maxDimension: window.cimoSettings?.maxImageDimension || 0,
initialQuality: 1, // Initial quality for smart optimization.
} )
}
}
Expand Down
Loading