Code Monkey home page Code Monkey logo

dominant-color-async's Introduction

Dominant color async

GitHub Workflow Status GitHub release (latest by date)

Calculate the dominant color for every image in WordPress, asynchronously

What does it do?

Dominant color async calculates the dominant color for images in your WordPress media gallery. It will also tell you if your image has transparency, or not. You can access this information using the dca_get_image_dominant_color and dca_get_image_transparency filters. This information will be calculated after you upload images in the media gallery.

Getting dominant color

$image_id = 123;

// Returns a hex code string or null if dominant color hasn't been calculated yet 
$dominant_color = apply_filters('dca_get_dominant_color', null, $image_id);

if ($dominant_color !== null) {
    echo "Image dominant color: " . $dominant_color;
} else if ($dominant_color === null) {
    echo "Image dominant color hasn't been calculated yet.";
}

Getting transparency

$image_id = 123;

// Returns either true, false or null if transparency hasn't been calculated yet
$has_transparency = apply_filters('dca_get_transparency', null, $image_id);

// Note: use strict comparison here instead of a shorthand to differentiate between false and null
if ($has_transparency === true) {
    echo "Image has transparency";
} else if ($has_transparency === false) {
    echo "Image doesn't have transparency";
} else if ($has_transparency === null) {
    echo "Image transparency hasn't been calculated yet.";
}

How is this different from Dominant Color plugin?

Dominant Color calculates the dominant color synchronously as you are uploading them. This can sometimes take a long time and lead to frustrating experience. Dominant color async will do this processing in the background using Action Scheduler library, leading to more fluid admin experience.

Dominant color async will also allow you to calculate color information for images missing it as a batch process. This makes it easy to integrate the plugin into an existing site.

One thing missing from this plugin is the "palette" functionality of Dominant Color which generates multiple dominant colors for single image and allows you to pick from one of these. If you need this functionality, then Dominant Color is a better choice.

Requirements

  • WordPress 5.0+
  • PHP 7.0+

Installation

  1. Download latest version on GitHub releases.
  2. Upload zip in WordPress admin plugins page or unzip in the wp-plugins directory
  3. See the plugin settings page under Media

dominant-color-async's People

Contributors

dependabot[bot] avatar joppuyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dominant-color-async's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.