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

Optimize computing dominant color and transparency for images by combining the two functions #381

Conversation

pbearne
Copy link
Contributor

@pbearne pbearne commented Jun 16, 2022

…or_has_transparency() functions into single function

Updated tests and improved the images
Introduced two new functions dominant_color_get_dominant_color() and dominant_color_has_transparency() that fetchs the date from image meta

Summary

Fixes #

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

…or_has_transparency() functions into single function

Updated tests and improved the images
Introduced two new functions dominant_color_get_dominant_color() and dominant_color_has_transparency() that fetchs the date from image meta
…or_has_transparency() functions into single function

Updated tests and improved the images
Introduced two new functions dominant_color_get_dominant_color() and dominant_color_has_transparency() that fetchs the date from image meta
@pbearne pbearne added this to the 1.3.0 milestone Jun 16, 2022
@pbearne pbearne added [Focus] Images Issues related to the Images focus area [Type] Enhancement A suggestion for improvement of an existing feature labels Jun 16, 2022
…or_has_transparency() functions into single function

Updated tests and improved the images
Introduced two new functions dominant_color_get_dominant_color() and dominant_color_has_transparency() that fetchs the date from image meta
$hex = dechex( imagecolorat( $shorted_image, 0, 0 ) );

if ( strlen( $hex ) < 6 ) {
return new WP_Error( 'image_editor_dominant_color_error', __( 'Dominant color detection failed.', 'performance-lab' ) );
}
return $hex;
return dechex( imagecolorat( $shorted_image, 0, 0 ) );
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this change a little more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are getting color with the shorten form #fff back from the underlining PHP code

Copy link
Member

Choose a reason for hiding this comment

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

I think it better to always return a 6 character hex here.

Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@pbearne I think the changes related to the issue look good for the most part, but this PR includes a bunch of additional changes which I think are out of scope as they do not relate to the underlying issue.

I think the only changes that are needed here are those in the load.php file (plus related tests). What is the reasoning for modifying the implementation of the image classes here? That seems out of scope.

modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
@felixarntz felixarntz added the [Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) label Jun 22, 2022
@felixarntz felixarntz changed the title Combined the dominant_color_get_dominant_color() and the dominant_col… Optimize computing dominant color and transparency for images by combining the two functions Jun 22, 2022
spacedmonkey and others added 10 commits June 22, 2022 22:55
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>

if ( strlen( $hex ) < 6 ) {
$rgb = imagecolorat( $shorted_image, 0, 0 );
$r = ( $rgb >> 16 ) & 0xFF;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

I pushed up some changed to add some more unit test coverage.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@pbearne Pretty much LGTM now. The remaining comments are minor, would be great if you could address them.

modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
modules/images/dominant-color/load.php Outdated Show resolved Hide resolved
spacedmonkey and others added 2 commits June 28, 2022 21:57
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@spacedmonkey Thanks for the quick iteration. LGTM! 🎉

@felixarntz felixarntz merged commit 6e0ff30 into WordPress:trunk Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Images Issues related to the Images focus area [Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid duplicate execution of setting up image editor when determining dominant color and transparency
3 participants