Until recently, I have been extracting the RGB colors from gif files using indentify -verbose. The results always gave me an array of colors in the expected form, #xxxxxx, which I then used in CSS, for setting color styles.
In PHP, the function I have been using to extract the colors is as follows:
preg_match('/([0-9]+):.*(#[0-9ABCDEFabcdef]+)[ ]*/', $hist, $color);
Previously, the $color variable always came through as a 6 digit RGB color.
Now I see that the colors are coming through with 8 digits instead of 6, #xxxxxxxx. Will someone please fill me in on what is happening and how to translate this new color scheme into a scheme that works with CSS?
Additionally, is there a more appropriate way to extract RGB colors from an image file rather than identify -verbose?
identify -verbose gives colors in #xxxxxxxx form
Re: identify -verbose gives colors in #xxxxxxxx form
Add +matte to your identify command line to turn off the alpha channel. An alpha channel expands to 8 hexadecimal values, 2 for each channel (RGBA).
You can extract the color values from the TXT image format:
You can extract the color values from the TXT image format:
- convert logo: logo.txt
more logo.txt
Re: identify -verbose gives colors in #xxxxxxxx form
Thanks, knowing that the last two digits were for the alpha channel helped me solve the problem, but not by using +matte. (I used substr($color,0,7) to get the RGB section of the color.)
When I tried to use +matte, I got no results at all. I guess the command string is incorrectly set up. Here is the command I used:
$exec_str = 'identify -verbose +matte ' . $image_dir . $image_file . ' > ' . $image_dir . 'hist.txt';
When I execute this I get no results. For example, after
exec($exec_str);
$hist_txt = file_get_contents($image_dir . 'hist.txt');
the $hist_txt variable is empty.
The following command, however, did work:
$exec_str = 'identify -verbose ' . $image_dir . $image_file . ' > ' . $image_dir . 'hist.txt';
When I tried to use +matte, I got no results at all. I guess the command string is incorrectly set up. Here is the command I used:
$exec_str = 'identify -verbose +matte ' . $image_dir . $image_file . ' > ' . $image_dir . 'hist.txt';
When I execute this I get no results. For example, after
exec($exec_str);
$hist_txt = file_get_contents($image_dir . 'hist.txt');
the $hist_txt variable is empty.
The following command, however, did work:
$exec_str = 'identify -verbose ' . $image_dir . $image_file . ' > ' . $image_dir . 'hist.txt';