Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #794 display the smaller size on image library data #810

Merged
merged 40 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f3c600a
Closes #763: AVIF support: UI (#769)
Miraeld Jan 3, 2024
fc76130
Closes #772: Changed webp to avif and slight modification to UI (#780)
Khadreal Jan 15, 2024
ec0bf15
Closes #766: Add avif format to picture element (#781)
jeawhanlee Jan 16, 2024
188264f
Add league/container, event-manager to composer and mozart (#782)
Khadreal Jan 18, 2024
1dc3a71
Add AVIF Rewrite rules (#774)
Miraeld Jan 18, 2024
0e8a3b1
AVIF settings update (#775)
Miraeld Jan 19, 2024
0a8f547
Add filter for nextgen image format #777 (#783)
Khadreal Jan 19, 2024
994c4eb
Feature/778 avif bulk generate (#784)
Khadreal Jan 23, 2024
de6dc98
Change methods name (#785)
Khadreal Jan 25, 2024
b396de2
Update WP background processing and Action Scheduler (#786)
remyperona Jan 29, 2024
19f6e4f
Fixes #791 Update texts related to WebP and Next-Gen (#800)
remyperona Feb 9, 2024
5d431cf
Merge branch 'develop' into feature/avif
remyperona Feb 14, 2024
fc23358
Fixes Container, Event Manager, CLI & Rewrite rules for AVIF (#797)
remyperona Feb 19, 2024
bde102e
:feat: Add check for avif image size to display on media page :closes…
Khadreal Feb 21, 2024
67bbc1b
Fixed lint error
Khadreal Feb 21, 2024
29f4bfb
Fixes #789 Fix error displayed when using generate missing next-gen v…
remyperona Feb 22, 2024
6c286ea
Fixes #788 Generate next-gen formats on image upload (#809)
remyperona Feb 22, 2024
2d98bbc
Closes #796: Auto generation of AVIF on save (#806)
Miraeld Feb 22, 2024
4502844
Closes #790, #792, #803: Delete/Generate next-gen in media not workin…
jeawhanlee Feb 22, 2024
6a64753
coding standards fixes
remyperona Feb 22, 2024
770c25f
update some occurences of webp to next-gen
remyperona Feb 22, 2024
2a14a1e
Modified the use of webp to nextgen close 794
Khadreal Feb 23, 2024
0103815
update text
remyperona Feb 24, 2024
a62dc23
update minified file
remyperona Feb 26, 2024
1cf2adc
remove dot from format
Khadreal Feb 27, 2024
e357b67
Fixes #815 Skip image deletion if returned path value is false (#819)
remyperona Feb 27, 2024
ead1038
Merge branch 'tester' into avif/media-library#794
Khadreal Feb 28, 2024
324c4fa
Closes #796: Auto AVIF Convertion on settings save (#811)
Miraeld Feb 28, 2024
4677279
Closes #822: The filter to enable webP along with AVIF is not working…
jeawhanlee Feb 28, 2024
85edeba
Fixes #826 Only generate missing next-gen when enabling AVIF option (…
remyperona Feb 29, 2024
f673ed2
Apply nginx rules for next gen images (#824)
wordpressfan Mar 1, 2024
6a7f2f3
Fix data for optimized medias without next-gen versions (#820)
remyperona Mar 1, 2024
96138a8
Merge branch 'feature/avif' into avif/media-library#794
Khadreal Mar 4, 2024
07f5377
:feat: Changed the order of media size to avif -> webp -> optimised
Khadreal Mar 4, 2024
8976b4c
fixed lint error
Khadreal Mar 4, 2024
7153e87
Resolve merge conflict
Khadreal Mar 11, 2024
7d93d51
merge develop and fixed code conflict
Khadreal Mar 13, 2024
6fce2ad
Merge commit 'daec1aca7e12badfac89a0a0170836a0fe568f95' into avif/med…
MathieuLamiot Mar 14, 2024
855858d
Fixed undefined error
Khadreal Mar 15, 2024
96717a1
:feat: Fixed undefined array key for image without webp version
Khadreal Mar 18, 2024
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
15 changes: 7 additions & 8 deletions classes/Bulk/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function run_optimize( string $context, int $optimization_level ) {
$result = $this->get_bulk_instance( $context )->get_optimized_media_ids_without_format( $format );
$media_ids['ids'] = array_merge( $media_ids['ids'], $result['ids'] );
}

$get_unoptimized_media_ids = $this->get_bulk_instance( $context )->get_unoptimized_media_ids( $optimization_level );

$media_ids['ids'] = array_merge( $media_ids['ids'], $get_unoptimized_media_ids );
Expand Down Expand Up @@ -597,20 +598,18 @@ public function bulk_get_stats_callback() {
* @param array $old_value The old option value.
* @param array $value The new option value.
*
* Please note that the convert_to_avif new value is a checkbox,
* so it equals 1 when it's set otherwise it's not set.
* That's why we need to use empty function when checking its value.
*
* @return void
*/
public function maybe_generate_missing_nextgen( $old_value, $value ) {
if ( empty( $old_value['convert_to_avif'] ) === empty( $value['convert_to_avif'] ) ) {
// Old value = new value so do nothing.
if ( isset( $old_value['convert_to_avif'] ) && isset( $value['convert_to_avif'] ) ) {
return;
}

if ( ! isset( $old_value['convert_to_avif'] ) && ! isset( $value['convert_to_avif'] ) ) {
return;
}

if ( empty( $value['convert_to_avif'] ) ) {
// new value is disabled, do nothing.
if ( isset( $value['convert_to_avif'] ) && ! (bool) $value['convert_to_avif'] ) {
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down
49 changes: 30 additions & 19 deletions classes/Optimization/Data/AbstractData.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,35 @@ public function get_original_size( $human_format = true, $decimals = 2 ) {

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) {
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true ) {
if ( ! $this->is_valid() ) {
return $human_format ? imagify_size_format( 0, $decimals ) : 0;
}

$data = $this->get_optimization_data();
$media = $this->get_media();
$data = $this->get_optimization_data();
$media = $this->get_media();
$format = 'webp';

if ( $use_webp ) {
$process_class_name = imagify_get_optimization_process_class_name( $media->get_context() );
$webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
}
$process_class_name = imagify_get_optimization_process_class_name( $media->get_context() );
$nextgen_avif_size_name = 'full' . constant( $process_class_name . '::AVIF_SUFFIX' );
$nextgen_webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );

if ( $use_webp && ! empty( $data['sizes'][ $webp_size_name ]['optimized_size'] ) ) {
$size = (int) $data['sizes'][ $webp_size_name ]['optimized_size'];
if ( $use_nextgen ) {
$size = (int) $data['sizes'][ $nextgen_webp_size_name ]['optimized_size'];
if ( ! empty( $data['sizes'][ $nextgen_avif_size_name ]['optimized_size'] ) ) {
$size = (int) $data['sizes'][ $nextgen_avif_size_name ]['optimized_size'];
}
} elseif ( ! empty( $data['sizes']['full']['optimized_size'] ) ) {
$size = (int) $data['sizes']['full']['optimized_size'];
} else {
Expand All @@ -320,18 +323,21 @@ public function get_optimized_size( $human_format = true, $decimals = 2, $use_we
// If nothing in the database, try to get the info from the file.
$filepath = false;

if ( $use_webp && ! empty( $data['sizes'][ $webp_size_name ]['success'] ) ) {
// Try with the WebP file first.
if ( $use_nextgen ) {
if ( ! empty( $data['sizes'][ $nextgen_avif_size_name ]['success'] ) ) {
$format = 'avif';
}
// Try with the Nextgen file first.
$filepath = $media->get_raw_fullsize_path();
$filepath = $filepath ? imagify_path_to_webp( $filepath ) : false;
$filepath = $filepath ? imagify_path_to_nextgen( $filepath, $format ) : false;

if ( ! $filepath || ! $this->filesystem->exists( $filepath ) ) {
$filepath = false;
}
}

if ( ! $filepath ) {
// No WebP? The full size then.
// No Nextgen? The full size then.
$filepath = $media->get_fullsize_path();
}

Expand Down Expand Up @@ -418,15 +424,20 @@ public function get_saving_percent() {
}

$process_class_name = imagify_get_optimization_process_class_name( $this->get_media()->get_context() );
$webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
$nextgen_webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
$nextgen_avif_size_name = 'full' . constant( $process_class_name . '::AVIF_SUFFIX' );

$percent = $this->get_size_data( $webp_size_name, 'percent' );
$percent = $this->get_size_data( $nextgen_avif_size_name, 'percent' );

// Check for webp version if avif is not found.
if ( ! $percent ) {
$percent = $this->get_size_data( 'full', 'percent' );
$percent = $this->get_size_data( $nextgen_webp_size_name, 'percent' );
}

$percent = $percent ? $percent : 0;
if ( ! $percent ) {
$percent = $this->get_size_data( 'full', 'percent' );
}
$percent = $percent ?: 0;

return round( (float) $percent, 2 );
}
Expand Down
6 changes: 3 additions & 3 deletions classes/Optimization/Data/DataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ public function get_original_size( $human_format = true, $decimals = 2 );

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true );
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true );


/** ----------------------------------------------------------------------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions classes/Optimization/Data/Noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ public function get_original_size( $human_format = true, $decimals = 2 ) {

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) {
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true ) {
return $human_format ? imagify_size_format( 0, $decimals ) : 0;
}

Expand Down
Loading