views:

296

answers:

1

I'm trying to use Imagick via php to generate a 8bit bmp from jpg. But i would like the pixel colors to start at index 16 rather than 0. The code below shows how to generate the bmp in the correct format i need, but the palette index defaults to 0. Is there a way to make sure the palette start at another index?

$average = new Imagick( "icon.jpg" );
$average->setCompression(Imagick::COMPRESSION_NO);
$average->quantizeImage( 32, Imagick::COLORSPACE_RGB, 0, false, false );
imagecolorset ($average, 0, 255, 255, 255);
$average->setImageFormat( "bmp" );

header( "Content-Type: image/bmp" );
echo $average;

$average->clear();
$average->destroy();
A: 

I don't think Imagick has anything built in for it, so you would have to create a new palette (copy colors from the old one with an offset) and then use $pixel = $average::getImagePixelColor() and then do $pixel->getColor() and $pixel->setColor() according to the new palette.

kb
i just found something i didn't know about; the ImagickPixelIterator class. that might be helpful in stepping through all pixles, found this blog about it http://valokuva.org/?p=79
kb
Thanks for pointing me the right directions. I was hoping there would be a more efficent process. The intension was to turn the resulting bmp into a pixmap, but it seems less intensive to alter the pixmap index than the bmp one, so I think I will go with that method. Thanks again for your help.
rikonholiday