The following command essentially applies a color lookup table (clut.png, a vertical gradient image) to another image (input.png, a greyscale image) to produce a colorized output image:
Code: Select all
convert input.png clut.png -fx "v.p{0,u*v.h}" output_cmd.png
Code: Select all
<?php
# load input file and color lookup file in a sequence
$im = new Imagick(array('input.png', 'clut.png'));
# apply fx operator (can't use clutImage for backwards compatibility)
$im->fxImage("v.p{0,u*v.h}");
# write output file
$im->writeImage('output_php.png');
I know there's a clutImage method specifically for this, but one of the environments I'm targeting for this has an older version of Imagemagick, so I wanted this for backward compatibility.
UPDATE: The reason fxImage seemed to be doing nothing was that I didn't realize it returns a new Imagick object rather than modifying the existing one. With that moment of stupidity realized, I grabbed the return value of the fxImage method, which seemed to be returning the expected image, but cropped to the dimensions of the color lookup table.
Code: Select all
# apply fx operator (can't use clutImage for backwards compatibility)
$im = $im->fxImage("u.p{0,v*u.h}");
Code: Select all
# load input file and color lookup file in a sequence
$im = new Imagick(array('clut.png', 'input.png'));
Code: Select all
# apply fx operator (can't use clutImage for backwards compatibility)
$im = $im->fxImage("u.p{0,v*u.h}");