Skip to content

Commit

Permalink
dominant color placeholder option
Browse files Browse the repository at this point in the history
  • Loading branch information
nosilver4u committed Apr 10, 2024
1 parent 0d02930 commit 4f8dd9d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
12 changes: 11 additions & 1 deletion classes/class-lazy-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ public function parse_img_tag( $image, $file = '' ) {
if ( $this->parsing_exactdn && \apply_filters( 'eio_use_lqip', $this->get_option( $this->prefix . 'use_lqip' ), $file ) ) {
$placeholder_types[] = 'lqip';
}
if ( $this->parsing_exactdn && \apply_filters( 'eio_use_dcip', $this->get_option( $this->prefix . 'use_dcip' ), $file ) ) {
$placeholder_types[] = 'dcip';
}
if ( $this->parsing_exactdn && \apply_filters( 'eio_use_piip', true, $file ) ) {
$placeholder_types[] = 'epip';
}
Expand All @@ -622,6 +625,14 @@ public function parse_img_tag( $image, $file = '' ) {
break 2;
}
break;
case 'dcip':
$this->debug_message( 'using dcip, maybe' );
if ( false === \strpos( $file, 'nggid' ) && ! \preg_match( '#\.svg(\?|$)#', $file ) && \strpos( $file, $this->exactdn_domain ) ) {
$placeholder_src = add_query_arg( array( 'lazy' => 3 ), $file );
$use_native_lazy = true;
break 2;
}
break;
case 'siip':
$this->debug_message( 'trying siip' );
// Can't use a relative width or height, so unset the dimensions in favor of not breaking things.
Expand Down Expand Up @@ -1155,7 +1166,6 @@ public function create_piip( $width = 1, $height = 1 ) {
$placeholder->clear();
}
// If that didn't work, and we have a premium service, use the API to generate the slimmest PIP available.
/* if ( $this->get_option( 'ewww_image_optimizer_cloud_key' ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_DISABLE_API_PIP' ) ) { */
if (
! \is_file( $piip_path ) &&
( $this->parsing_exactdn || $this->get_option( 'ewww_image_optimizer_cloud_key' ) ) &&
Expand Down
2 changes: 2 additions & 0 deletions classes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ public function register_settings() {
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_lazy_load', 'boolval' );
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_ll_autoscale', 'boolval' );
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_use_lqip', 'boolval' );
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_use_dcip', 'boolval' );
// Using sanitize_text_field instead of textarea on purpose.
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_ll_all_things', 'sanitize_text_field' );
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_ll_exclude', array( $this, 'exclude_paths_sanitize' ) );
Expand Down Expand Up @@ -694,6 +695,7 @@ public function set_defaults() {
\add_option( 'ewww_image_optimizer_lazy_load', false );
\add_option( 'ewww_image_optimizer_use_siip', false );
\add_option( 'ewww_image_optimizer_use_lqip', false );
\add_option( 'ewww_image_optimizer_use_dcip', false );
\add_option( 'ewww_image_optimizer_ll_exclude', '' );
\add_option( 'ewww_image_optimizer_ll_all_things', '' );
\add_option( 'ewww_image_optimizer_disable_pngout', true );
Expand Down
18 changes: 18 additions & 0 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ function ewww_image_optimizer_save_network_settings() {
update_site_option( 'ewww_image_optimizer_ll_autoscale', $ewww_image_optimizer_ll_autoscale );
$ewww_image_optimizer_use_lqip = ( empty( $_POST['ewww_image_optimizer_use_lqip'] ) ? false : true );
update_site_option( 'ewww_image_optimizer_use_lqip', $ewww_image_optimizer_use_lqip );
$ewww_image_optimizer_use_dcip = ( empty( $_POST['ewww_image_optimizer_use_dcip'] ) ? false : true );
update_site_option( 'ewww_image_optimizer_use_dcip', $ewww_image_optimizer_use_dcip );
// Using sanitize_text_field instead of textarea on purpose.
$ewww_image_optimizer_ll_all_things = empty( $_POST['ewww_image_optimizer_ll_all_things'] ) ? '' : sanitize_text_field( wp_unslash( $_POST['ewww_image_optimizer_ll_all_things'] ) );
update_site_option( 'ewww_image_optimizer_ll_all_things', $ewww_image_optimizer_ll_all_things );
Expand Down Expand Up @@ -11504,6 +11506,7 @@ function ewwwio_debug_info() {
ewwwio_other_lazy_detected();
ewwwio_debug_message( 'LL autoscale: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_ll_autoscale' ) ? 'on' : 'off' ) );
ewwwio_debug_message( 'LQIP: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_lqip' ) ? 'on' : 'off' ) );
ewwwio_debug_message( 'DCIP: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_dcip' ) ? 'on' : 'off' ) );
ewwwio_debug_message( 'S(VG)IIP: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_siip' ) ? 'on' : 'off' ) );
ewwwio_debug_message( 'external CSS background (all things): ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_ll_all_things' ) );
ewwwio_debug_message( 'LL exclusions:' );
Expand Down Expand Up @@ -12948,6 +12951,9 @@ class_exists( 'EWWW\ExactDN' ) &&
$lqip_che = ( ( is_multisite() && is_network_admin() ) || is_object( $exactdn ) ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_lqip' );
$lqip_id = ! is_network_admin() && ! $exactdn_enabled ? 'ewww_image_optimizer_use_lqip_disabled' : 'ewww_image_optimizer_use_lqip';
$lqip_dis = ! is_network_admin() && ! $exactdn_enabled;
$dcip_che = ( ( is_multisite() && is_network_admin() ) || is_object( $exactdn ) ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_dcip' );
$dcip_id = ! is_network_admin() && ! $exactdn_enabled ? 'ewww_image_optimizer_use_dcip_disabled' : 'ewww_image_optimizer_use_dcip';
$dcip_dis = $lqip_dis;
$ll_exclude_paths = ewww_image_optimizer_get_option( 'ewww_image_optimizer_ll_exclude' ) ? implode( "\n", (array) ewww_image_optimizer_get_option( 'ewww_image_optimizer_ll_exclude' ) ) : '';
$current_jpeg_quality = apply_filters( 'jpeg_quality', 82, 'image_resize' );
$webp_php_rewriting = ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_picture_webp' );
Expand Down Expand Up @@ -13325,6 +13331,7 @@ class_exists( 'EWWW\ExactDN' ) &&
</tr>
<?php if ( ! $exactdn_enabled ) : ?>
<input type='hidden' id='ewww_image_optimizer_use_lqip' name='ewww_image_optimizer_use_lqip' <?php echo ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_lqip' ) ? "value='1'" : "value='0'" ); ?> />
<input type='hidden' id='ewww_image_optimizer_use_dcip' name='ewww_image_optimizer_use_dcip' <?php echo ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_use_dcip' ) ? "value='1'" : "value='0'" ); ?> />
<?php endif; ?>
<tr class="ewwwio-exactdn-options" <?php echo $exactdn_enabled ? '' : 'style="display:none;"'; ?>>
<td>&nbsp;</td>
Expand Down Expand Up @@ -13462,6 +13469,17 @@ class_exists( 'EWWW\ExactDN' ) &&
</p>
</td>
</tr>
<tr id='ewww_image_optimizer_dcip_container' <?php echo ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) ? '' : ' style="display:none"'; ?>>
<td>&nbsp;</td>
<td>
<input type='checkbox' name='ewww_image_optimizer_use_dcip' value='true' id='<?php echo esc_attr( $dcip_id ); ?>' <?php disabled( $dcip_dis ); ?> <?php checked( $dcip_che ); ?> />
<label for='<?php echo esc_attr( $dcip_id ); ?>'><strong>DCIP</strong></label>
<?php ewwwio_help_link( 'https://docs.ewww.io/article/75-lazy-load-placeholders', '5c9a7a302c7d3a1544615e47' ); ?>
<p class='description'>
<?php esc_html_e( 'Use dominant-color versions of your images as placeholders via Easy IO. Can improve user experience, but may be slower than blank placeholders.', 'ewww-image-optimizer' ); ?>
</p>
</td>
</tr>
<tr id='ewww_image_optimizer_ll_all_things_container' <?php echo ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) ? '' : ' style="display:none"'; ?>>
<td>&nbsp;</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions ewww-image-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
Description: Smaller Images, Faster Sites, Happier Visitors. Comprehensive image optimization that doesn't require a degree in rocket science.
Author: Exactly WWW
Version: 7.5.0.1
Version: 7.5.0.2
Requires at least: 6.1
Requires PHP: 7.3
Author URI: https://ewww.io/
Expand All @@ -34,7 +34,7 @@
add_action( 'admin_notices', 'ewww_image_optimizer_dual_plugin' );
} elseif ( false === strpos( add_query_arg( '', '' ), 'ewwwio_disable=1' ) ) {

define( 'EWWW_IMAGE_OPTIMIZER_VERSION', 750.1 );
define( 'EWWW_IMAGE_OPTIMIZER_VERSION', 750.2 );

if ( WP_DEBUG && function_exists( 'memory_get_usage' ) ) {
$ewww_memory = 'plugin load: ' . memory_get_usage( true ) . "\n";
Expand Down
2 changes: 2 additions & 0 deletions includes/eio-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,14 @@ jQuery(document).ready(function($) {
$('#ewww_image_optimizer_ll_all_things_container').fadeIn();
$('#ewww_image_optimizer_siip_container').fadeIn();
$('#ewww_image_optimizer_lqip_container').fadeIn();
$('#ewww_image_optimizer_dcip_container').fadeIn();
} else {
$('#ewww_image_optimizer_ll_exclude_container').fadeOut();
$('#ewww_image_optimizer_ll_autoscale_container').fadeOut();
$('#ewww_image_optimizer_ll_all_things_container').fadeOut();
$('#ewww_image_optimizer_siip_container').fadeOut();
$('#ewww_image_optimizer_lqip_container').fadeOut();
$('#ewww_image_optimizer_dcip_container').fadeOut();
}
});
$('#ewww_image_optimizer_webp_for_cdn, #ewww_image_optimizer_picture_webp').on(
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ That's not a question, but since I made it up, I'll answer it. See this resource

= 7.5.1 =
*Release Date - TBD*
* added: Lazy Load can use dominant color placeholders via Easy IO
* added: ability to filter/parse admin-ajax.php requests via eio_filter_admin_ajax_response filter
* changed: improved smoothing of LQIP for Lazy Load when using Easy IO
* fixed: async bulk interface does not show Start Optimizing when image queue is already visible
* fixed: bulk process appears to have completed after clearing queue

Expand Down

0 comments on commit 4f8dd9d

Please sign in to comment.