aryehraber/statamic-color-extractor
A Statamic addon that extracts a color palette from images, letting you pull dominant colors from assets and use them in templates, CSS, or design accents without manual picking.
composer require aryehraber/statamic-color-extractor. The addon is auto-discovered by Statamic (no manual provider registration needed on Statamic 3+).php artisan vendor:publish and pick the color-extractor tag (or copy vendor/aryehraber/statamic-color-extractor/config/color-extractor.php manually). This file is where extraction behaviour lives.config/color-extractor.php, src/Listeners (new in v2.1.0), and src/Commands. Those four cover ~90% of day-to-day questions.php please list — the addon exposes an extraction command, and v2.1.0's headline feature is that you no longer have to call it for new uploads.color field to an asset container's blueprint so the extracted value is visible/editable in the CP, upload an image, then output it in Antlers: {{ hero_image:color }}. Typical first win is a CSS custom property or an inline background-color behind a lazy-loaded image.Placeholder / blur-up pattern. Store the extracted hex as a CSS variable and paint it behind the <img> so layout and colour are correct before the image loads:
<div style="background-color: {{ hero_image:color }}">
<img src="{{ hero_image:url }}" loading="lazy" alt="">
</div>
Auto-extraction as the default path (v2.1.0). With the event listener enabled, colours are computed when an asset is uploaded/saved, so templates can assume :color exists for new content. Keep the command in your deploy or content-import scripts for anything that bypasses the CP (migrations, imports, syncs, seeders).
Backfill as a one-off job. For an existing asset library, run the command once after deploy. On a large library, prefer running it in a queued context or per-container rather than in a request — and clear the Stache afterwards so templates see the new meta.
Reacting to extraction. Rather than duplicating extraction logic, subscribe to the addon's event (or bind your own listener alongside the built-in one) to derive complementary colours, compute contrast text colour, or push the value into a search index. This keeps you upstream-compatible.
Manual override workflow. If editors occasionally need to correct a colour, treat the extractor as a default-filler: either disable the listener for those containers in config, or guard your own listener so it only writes when the field is empty. This is a policy decision to make explicitly — see Gotchas.
Container-by-container rollout. Roll out to one asset container at a time, verify CP output and template behaviour, then widen. Colours on a 5,000-image library are a different operational problem from colours on a logo folder.
config/color-extractor.php will not pick them up. Diff your published config against the vendor copy after every minor bump, or you'll silently run on defaults.php please stache:clear, php please clear:cache, plus any CDN/page cache) before concluding it didn't work.color is derived or editorial, and enforce it in config or in your own listener.{{ hero_image:color or="#eeeeee" }} or an ?? equivalent in Blade).storage/logs/laravel.log first when "uploading this one image errors" is reported).How can I help you explore Laravel packages today?