Skip to content

Image optimization - replace original with scaled images - #883

Merged
hi-hai merged 1 commit into
litespeedtech:devfrom
timotei-litespeed:Img_Opm-option_scaled
Aug 18, 2025
Merged

Image optimization - replace original with scaled images#883
hi-hai merged 1 commit into
litespeedtech:devfrom
timotei-litespeed:Img_Opm-option_scaled

Conversation

@timotei-litespeed

Copy link
Copy Markdown
Contributor

Allow users to replace original image with the scaled version of image.
Will allow user to change scaled size by using filter big_image_size_threshold. More info: https://developer.wordpress.org/reference/hooks/big_image_size_threshold/

@timotei-litespeed timotei-litespeed changed the title QC Image optimization - replace original with scaled images Image optimization - replace original with scaled images Jul 31, 2025
Comment thread tpl/img_optm/settings.tpl.php Outdated
@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch from 54503c1 to 5191fc9 Compare August 12, 2025 05:39
Comment thread src/img-optm.cls.php Outdated
Comment thread src/media.cls.php Outdated
@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch from ca725ca to 77a7343 Compare August 14, 2025 06:04
Comment thread src/lang.cls.php Outdated
@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch 2 times, most recently from 182613e to 1293945 Compare August 14, 2025 15:24
Comment thread src/media.cls.php Outdated
// Test if create and image was resized.
if( "create" === $context && isset($metadata['original_image']) && isset($metadata['file']) && false !== strstr($metadata['file'], '-scaled')){
// Get rescaled file name.
$path_exploded = explode( DIRECTORY_SEPARATOR, strrev($metadata['file']), 2 );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotei-litespeed why use DIRECTORY_SEPARATOR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used '/' instead of DIRECTORY_SEPARATOR to keep constinency

Comment thread src/media.cls.php Outdated
$rescaled_path = $base_path . $rescaled_file_name;
$new_path = $base_path . $metadata['original_image'];

if( is_file( $rescaled_path ) && is_file( $rescaled_path ) ){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotei-litespeed Please read Media->info() func and get the idea how to check existence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes to code :)

@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch from 1293945 to 9c8b913 Compare August 14, 2025 15:37
Comment thread src/media.cls.php
@hi-hai

hi-hai commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator

@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch 2 times, most recently from b2e830f to ba6c7cf Compare August 14, 2025 16:41
@hi-hai

hi-hai commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator

Both check existence and rename, you all need use API instead of direct php func.

This PR will have to be in v7.5.

Text review
Review fixes
Move to Media settings
@Tymotey
Tymotey force-pushed the Img_Opm-option_scaled branch from ba6c7cf to be62b7b Compare August 18, 2025 16:06
@hi-hai
hi-hai merged commit 2b4e335 into litespeedtech:dev Aug 18, 2025
1 check passed
@timotei-litespeed
timotei-litespeed deleted the Img_Opm-option_scaled branch August 28, 2025 18:14
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.

3 participants