From 4b1f2ffa257ecf218abb2a5b8e89e1b0c44b1eb6 Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Tue, 14 Apr 2026 10:40:35 +0800 Subject: [PATCH 1/2] fix: get lesser between wp threshold and user max dimension --- src/admin/class-script-loader.php | 5 +++++ src/shared/converters/index.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/admin/class-script-loader.php b/src/admin/class-script-loader.php index 8b67131..d04ef04 100644 --- a/src/admin/class-script-loader.php +++ b/src/admin/class-script-loader.php @@ -77,6 +77,10 @@ public static function enqueue_cimo_assets() { // Get current settings $settings = get_option( 'cimo_options', [] ); + // Expose threshold for WP Core's big image scaling. + // Can be false when auto scaling is disabled. + $threshold = apply_filters( 'big_image_size_threshold', 2560 ); + // Localize script with REST API URL, nonce, and settings wp_localize_script( 'cimo-script', @@ -100,6 +104,7 @@ public static function enqueue_cimo_assets() { 'svgUpload' => isset( $settings['svg_upload'] ) ? (int) $settings['svg_upload'] : 0, 'svgOptimizationEnabled' => isset( $settings['svg_optimization_enabled'] ) ? (int) $settings['svg_optimization_enabled'] : 1, 'stealthModeEnabled' => isset( $settings['stealth_mode_enabled'] ) ? (int) $settings['stealth_mode_enabled'] : 0, + 'wpScalingThreshold' => $threshold, ] ); diff --git a/src/shared/converters/index.js b/src/shared/converters/index.js index 7a58c50..b3769e3 100644 --- a/src/shared/converters/index.js +++ b/src/shared/converters/index.js @@ -38,6 +38,16 @@ export const getFileConverter = _file => { } if ( file.type.startsWith( 'image/' ) ) { + const max = parseFloat( window.cimoSettings?.maxImageDimension || 0 ) + const wp = parseFloat( window.cimoSettings?.wpScalingThreshold || 0 ) + + // Determine the final max dimension to use for conversion, + // prioritizing the lower of the two thresholds if both are set. + // 0 means no max dimension. + const finalMaxDimension = max && wp + ? Math.min( max, wp ) + : max || wp || 0 + // If the browser doesn't support webp, then we can't convert it. if ( ! isFormatSupported( 'webp' ) ) { return new NullConverter( file ) @@ -46,7 +56,7 @@ export const getFileConverter = _file => { return new ImageConverter( file, { format: 'webp', quality: window.cimoSettings?.webpQuality || 0.8, - maxDimension: window.cimoSettings?.maxImageDimension || 0, + maxDimension: finalMaxDimension, } ) } } From 51f17f2b111f299ab239c641fe26a8df95344b0e Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Fri, 17 Apr 2026 10:34:40 +0800 Subject: [PATCH 2/2] fix: change of placeholder and description for image max dimension --- src/admin/js/page/admin-settings.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/admin/js/page/admin-settings.js b/src/admin/js/page/admin-settings.js index 270f000..636df5e 100644 --- a/src/admin/js/page/admin-settings.js +++ b/src/admin/js/page/admin-settings.js @@ -591,8 +591,9 @@ const AdminSettings = () => { label={ __( 'Maximum Image Dimension', 'cimo-image-optimizer' ) } type="number" value={ settings.maxImageDimension } + placeholder="2560" onChange={ value => handleInputChange( 'maxImageDimension', value ) } - help={ __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to disable resizing. We recommend a value of 1920px.', 'cimo-image-optimizer' ) } + help={ __( 'Maximum width or height in pixels for uploaded images. Images exceeding this dimension will be automatically resized while preserving aspect ratio. Leave empty to use the WordPress maximum dimension (2560px). We recommend a value of 1920px.', 'cimo-image-optimizer' ) } __next40pxDefaultSize />