Skip to content
Merged
Changes from 1 commit
Commits
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
Next Next commit
Fix focal point issue
  • Loading branch information
mukeshpanchal27 committed Nov 15, 2022
commit 90b29c3efe565e20738c5babf6b6f60e1cad98f6
12 changes: 8 additions & 4 deletions modules/images/dominant-color/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ function dominant_color_img_tag_add_dominant_color( $filtered_image, $context, $
}

$data = '';
$style = '';
$extra_class = '';

if ( ! empty( $image_meta['dominant_color'] ) ) {
$data .= sprintf( 'data-dominant-color="%s" ', esc_attr( $image_meta['dominant_color'] ) );
$style = 'style="--dominant-color: #' . esc_attr( $image_meta['dominant_color'] ) . ';" ';
if ( str_contains( $filtered_image, ' style="' ) ) {
$filtered_image = str_replace( ' style="', ' style="--dominant-color: #' . esc_attr( $image_meta['dominant_color'] ) . ';', $filtered_image );
} else {
$filtered_image = str_replace( '<img ', '<img style="--dominant-color: #' . esc_attr( $image_meta['dominant_color'] ) . ';" ', $filtered_image );
}
}

if ( isset( $image_meta['has_transparency'] ) ) {
Expand All @@ -126,9 +129,10 @@ function dominant_color_img_tag_add_dominant_color( $filtered_image, $context, $
$extra_class = $image_meta['has_transparency'] ? 'has-transparency' : 'not-transparent';
}

if ( ! empty( $data ) || ! empty( $style ) ) {
$filtered_image = str_replace( '<img ', '<img ' . $data . $style, $filtered_image );
if ( ! empty( $data ) ) {
$filtered_image = str_replace( '<img ', '<img ' . $data, $filtered_image );
}

if ( ! empty( $extra_class ) ) {
$filtered_image = str_replace( ' class="', ' class="' . $extra_class . ' ', $filtered_image );
}
Expand Down