I'm trying to create a map of the United States that updates as US presidential candidates are declared the winner of different states. To do this I have a bunch of state pictures in various colors (red, blue, striped, etc..) which I will stitch together to create the full map and save it as an image.
The state images are all jpegs and I don't have the ability to turn them into a format that supports transparency. My question is how do I make the white background of these .jpg images transparent once I have pulled them into Imagick?
I have the following code which only shows the last image that was added to the map because its white background is covering the rest.
$us_map = new Imagick();
$us_map->newImage(
self::MAP_WIDTH,
self::MAP_HEIGHT,
new ImagickPixel('none'),
);
$us_map->setFormat('png');
foreach ($curls as $curl) {
$state = new Imagick();
$state->readImageBlob($curl->getBody());
// What do I do here to change all white in $state to transparent?
$us_map->addImage($state);
}
$file_name = '/tmp/pic.US_MAP.'.request_time().'.png';
$us_map->writeImage($file_name);