Generating Color Palette Using ColdFusion & ImageMagick

James Moberg - Mar 11 '20 - - Dev Community

I read Ben Nadel's recent ColdFusion post on Exploring Color Histograms In GraphicsMagick And Lucee CFML 5.2.9.31 and thought I'd compare it with ImageMagick.

ImageMagick returns a list of color data in a low-to-high order. I used ReMatch to identify the hex colors via regex, generated an array and then reversed it.

NOTE: I wanted to compare performance using Ben's script, but his "Lucee CFML" script wasn't written to be compatible with ColdFusion 2016. :(

Usage

colors = extractPalette(imagePath, numberOfColors);
Enter fullscreen mode Exit fullscreen mode

Source Code

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .