Improvement suggestion:
I reckon you should change the upload behaviour to use a thumbnail of the image rather than the original.
When editors upload 50mb images because they just don’t care, it all grinds to a halt while the plugin sniffs at the huge image.
Although get_post_meta( get_post_thumbnail_id(), ‘dominant_color_hex’, true );
definitely works, it only gets the automatically selected color. It does not change when you select one of the 8 colors generated.
Use get_color_data( get_post_thumbnail_id(), ‘dominant_color_hex’, true );
if you want to fix this.
For anyone wanting to set the text color based on the brightness of the dominant color, I created this function.
function dc_dynamic_color( $color, $dark = '#000', $light = '#FFF' ) {
/* Dynamic Text Color */
$hex = str_replace("#", "", $color);
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
if ($r + $g + $b > 382) {
$text_color = $dark;
} else {
$text_color = $light;
}
return $text_color;
}
add_action( '', 'dc_dynamic_color' );
dc_dynamic_color('#bc130b')
would return #FFF.
You can also pass css classes in $dark
and $light
.
NOTE: You must use hexadecimal for $color
.
Hi,
great plugin.
First: Please fix this bug: https://www.ads-software.com/support/topic/calculate-now
Second: Please use the register_uninstall_hook()
to delete all values from _postmeta table once the user deletes the plugin. Otherwise the user will be left with lots of abandoned entries.
Thank you.
]]>Hi Liam
I love the idea of this plugin! So very useful however, when I try to call up the results for use on the front end using get_post_meta( $post->ID, 'dominant_color_hex', true )
I get nothing. Not even an empty array.
With some combinations of various functions I can get the ‘alt’, ‘caption’, and ‘description’ of the image but nothing from the dominant colour plugin…
It works perfectly in the admin and displays a colour palette for each image with the dominant colour selected.
I have tried calling it from both within the loop and outside the loop both including and excluding the true/false parameter. Nothing.
Any thoughts??
Thank you.
]]>Hi,
Great plugin : it works fine with new upload>
I try to add palette to old attachment: I hit “Calculate Now!’but nothing happens.
The Console says: unable to found attachDominantColor. I put the script line before the trigger (line 81, dominant-color.php). No error in the console, but still no result…
Do you have an idea?
Thanks, Ju
]]>Hi,
I love the idea of your plugin and have been searching for something like this for a while. I’m aiming for a “Dribbble” style look, where my posts have a small palette displaying the dominant colors of the featured image.
The plugin seems to generate the colors in the media library perfectly, but then I’m having trouble displaying it on my posts. I have a “Get Custom Field” plugin too, but it’s not able to display any of the rgb/hex meta.
Do you have any ideas or an example php code I could add in to my post as I am a bit of a novice?
Many thanks for any help!
Michael.
– Also, will it work on Custom Post Types?
Thanks!
]]>