Giter Club home page Giter Club logo

craft-colorextractor's Introduction

Color Extractor

Extract colors from image assets in Craft 3. The Craft 2 plugin is moved to another branch.

Inner working

By using the imageColor field on each asset, it doesn't require extra database queries when showing colors. On install it creates a task to extract the color for every image.

Requirements

  • A field named imageColor on all assets of kind image (can be color or plaintext)
  • Craft 3 (we test on the latest release of Craft 3)
  • PHP 7.1 at least

Example usage

Use the colorExtractor twig filter to retrieve the image's color from templates.

<div style="background-color: {{ entry.images[0]|colorExtractor }};"></div>

From command:

craft color-extractor/default

License

Copyright © Born05

See license

Credits

Based upon craft-image-color plugin by familiar-studio.

craft-colorextractor's People

Contributors

dpschen avatar nstcactus avatar roelvanhintum avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

craft-colorextractor's Issues

Error during install

After installing this plugin, message appears:

Color Extractor has been added, but an error occurred when installing it.
yii\base\UnknownMethodException: Calling unknown method: craft\elements\db\AssetQuery::imageColor()

Plugins seems to be properly installed however, it shows up on settings/plugins list.

Error on install task

Hello,
after installing the ColorExtractorTask fails to run through. In the queue.log I found the following:

2019-01-24 17:59:27 [-][18][-][error][craft\queue\QueueLogBehavior::afterError]  [7770] ColorExtractorTask (attempt: 1) - Error (time: 0.343s): imagecreatefromstring(): Data is not in a recognized format
2019-01-24 17:59:27 [-][18][-][error][yii\base\ErrorException:2] yii\base\ErrorException: imagecreatefromstring(): Data is not in a recognized format in /var/www/html/vendor/league/color-extractor/src/League/ColorExtractor/Palette.php:54
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yii\base\ErrorHandler->handleError(2, 'imagecreatefrom...', '/var/www/html/v...', 54)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'imagecreatefrom...', '/var/www/html/v...', 54, Array)
#2 /var/www/html/vendor/league/color-extractor/src/League/ColorExtractor/Palette.php(54): imagecreatefromstring('II*\x00\xEE\x90\x15\x00\x802\xD8\xAB\xF2\x98D...')
#3 /var/www/html/vendor/born05/craft-colorextractor/src/services/Asset.php(32): League\ColorExtractor\Palette::fromFilename([<!-- STRING WITH CROPPED URL (PROBABLY IMAGE) -->])
#4 /var/www/html/vendor/born05/craft-colorextractor/src/services/Asset.php(57): born05\colorextractor\services\Asset->extractColor(Object(craft\elements\Asset))
#5 /var/www/html/vendor/born05/craft-colorextractor/src/jobs/ColorExtractorTask.php(44): born05\colorextractor\services\Asset->getImageColor(Object(craft\elements\Asset), true)
#6 /var/www/html/vendor/yiisoft/yii2-queue/src/Queue.php(214): born05\colorextractor\jobs\ColorExtractorTask->execute(Object(craft\queue\Queue))
#7 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(147): yii\queue\Queue->handleMessage('7770', 'O:45:"born05\\co...', '300', 1)
#8 /var/www/html/vendor/craftcms/cms/src/queue/Queue.php(96): yii\queue\cli\Queue->handleMessage('7770', 'O:45:"born05\\co...', '300', 1)
#9 /var/www/html/vendor/craftcms/cms/src/controllers/QueueController.php(86): craft\queue\Queue->run()
#10 [internal function]: craft\controllers\QueueController->actionRun()
#11 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#13 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('run', Array)
#14 /var/www/html/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('run', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('queue/run', Array)
#16 /var/www/html/vendor/craftcms/cms/src/web/Application.php(561): craft\web\Application->runAction('queue/run', Array)
#17 /var/www/html/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#18 /var/www/html/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#19 /var/www/html/web/index.php(21): yii\base\Application->run()
#20 {main}

Image must be a gd resource

Hi,
I've got some ColorExtractorTask error in the Task manager but I'm unable to figure why.
It happen when the site editors users are creating some ressource entries.
I'm unable to reproduce this error.

The error message is "Image must be a gd resource".

When I manually upload the very same image file that cause the error, there is no such error and the Color Extractor Field is correctly populated.

How can I debug this?

Thanks for your help.

Enhancement: Color Extractor Task/Job Name

As some of my ColorExtractorTasks sometimes fail (#4), it would be nice to have the image name inside the task. Something like CE: myImageName.jpg. (probably need to truncate the name in case it's too long).
Otherwise it's quite hard to identify which image failed.

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.