Color substitutions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Color substitutions

Post by stevenb46 »

Hi,

I'm trying to convert Adobe EPS (Illustrator/Photoshop) graphics to JPG with imagemagick, which works, but trying to replace colors in the EPS graphic from a Pantone (C=0, M=59.85, Y=100, K=0) color with RGB (R=255, G=133, B=0) in JPG format. I'm not sure how to do this, can someone offer some assistance? Imagemagick is close, but not perfect on the conversion, just trying to tweek the jpg conversion a bit.

Thanks in Advance!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color substitutions

Post by fmw42 »

IM substitutes color only in RGB mode as far as I know. If you provide CMYK colors they are converted to RGB to do any substitution. So I believe you would need to convert your CMYK eps to sRGB, substitute colors, then if you want a CMYK JPG convert it back to CMYK. With vector images such as EPS, you need to specify the color conversion (-colorspace sRGB) before reading in the EPS file.

It would help to have your EPS file and any command line and result that you have tried.

To change colors, you could do something like

Code: Select all

convert -colorspace sRGB -density XX image.eps -fill newcolor -opaque oldcolor -quality XX result_rgb.jpg
or

Code: Select all

convert -colorspace sRGB -density XX image.eps -fill newcolor -opaque oldcolor -colorspace CMYK -quality XX result_cmyk.jpg
You may bet better conversion back to CMYK by using profiles rather than -colorspace
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

Thanks, I really haven't tried anything yet. All I know is the CMYK formula from Illustrator (and the Pantone name), which was given and what I need is that color to convert to the RGB values above in the JPG. By default, IM is giving me R=240, G=127, B=45. which is off from what I need.

I don't know anything about colorspace, color matrix, profiles or any sort color manipulation as mentioned in the online manual and that is difficult to understand. One other note, going from vector to raster, will need antialias turned, on, so that one color I need will turn into multiple variations from that new color. A version of black and white is in the graphic as well, though there is no complaints of those. The only one I've been asked to change is the color above. I hope antialias is applied after color change.

Thanks,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color substitutions

Post by fmw42 »

It would help to have your EPS file and any command line and result that you have tried. You can post it to any free image hosting service such as dropbox.com, that does not change the eps to something else. Then post the URL here.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color substitutions

Post by snibgo »

stevenb46 wrote:... in the JPG. By default, IM is giving me R=240, G=127, B=45. which is off from what I need.
JPG is a lossy format, which means it mangles the colours. Don't bother testing what you get in JPG. Instead, convert to PNG or other lossless format and test that result.

An Illustrator image is likely to have flat colours which don't compress well in JPG, and will get badly mangled.
stevenb46 wrote:I hope antialias is applied after color change.
If IM is doing the colour change, it will occur to the raster after the anti-aliasing, which is done by a delegate (Ghostscript).
snibgo's IM pages: im.snibgo.com
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

I tried:

convert -colorspace sRGB -density 1000 "c:\eps\im\g51n34.eps -fill "rgb(255,131,0)" -opaque "cmyk(0, 60, 100, 0)" -antialias -colorspace CMYK -quality 100 -resize 10% "c:\eps\im\g51n34.jpg

but I get errors looks like its erroring out around cmyk. Is this legal?

JPG is required, I don't have the option of a different format.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color substitutions

Post by snibgo »

If you have a quote at the start of both filenames you also need them at the ends.

You can still test with PNG even if you then switch to JPG for the live version.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color substitutions

Post by fmw42 »

If you resize after changing colors, you will get different colors afterwards due to the resampling/filtering involved in the resize
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

k, thanks, I didn't see it. Now no errors, but the color is coming out RGB 233,142,61 (I was getting 240,127,45 with no color adjustments and want 255,131,0)
So here's the latest.

convert -colorspace sRGB -density 1000 "c:\eps\im\g51n34.eps" -fill "rgb(255,131,0)" -opaque "cmyk(0, 59.85, 100, 0)" -antialias -colorspace CMYK -quality 100 -resize 10% "c:\eps\im\g51n34.jpg"

BTW, the image is coming out 72dpi, it should be 100dpi? Any idea why? The original eps was 100dpi. I know this has something to do with -density and the resize. The jpg was coming out cloudy without these settings, but it apparently increased the size of the graphic. I was thinking 10x the original size, and then 10% of the eps.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color substitutions

Post by snibgo »

"-antialias" is the default setting. Putting this in your command should have no effect.

Please upload the image to somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

Sorry, I'm not allowed to share the graphic.

I tried this:

convert "c:\eps\im\g51n34.eps" -antialias -quality 100 "c:\eps\im\g51n34.png"
convert -colorspace RGB "c:\eps\im\g51n34.png" -fill "rgb(255,131,0)" -opaque "rgb(240,127,45)" -colorspace RGB -quality 100 "c:\eps\im\g51n34.jpg"

Now I'm getting
RGB 255,104,1

Why?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color substitutions

Post by snibgo »

What is your first "-colorspace RGB" for?

What is your second "-colorspace RGB" for? Why are you using RGB instead of sRGB?

How are you testing the output pixel value (255,104,1)?

Using JPG as output WILL give an unexpected number. Please test with PNG, not JPG.
snibgo's IM pages: im.snibgo.com
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

as I said previously, I don't know -colorspace spec. I re-looked at the color of the 1st conversion, that was off. I changed it as below.

I tried this:

convert "c:\eps\im\g51n34.eps" -antialias -quality 100 "c:\eps\im\g51n34a.png"
convert -colorspace sRGB "c:\eps\im\g51n34a.png" -fill "rgb(255,131,0)" -opaque "rgb(255,103,0)" -quality 100 "c:\eps\im\g51n34.png"
convert "c:\eps\im\g51n34.png" -quality 100 "c:\eps\im\g51n34.jpg"

g51n34a.png = RGB 255,103,0
g51n34.png = RGB 255,131,0 (ON THE MONEY!)
g51n34.jpg = RGB 255,130,1 (off???)

I know you said don't use JPG, but I have no choice that is the expected output (for the Web). Why the color diff? I'm going to have to find a different conversion utility, like GIMP if I cannot reliably control the colors. Also, how can I improve the output. The size above at -density 1000, at 10% resize had turned a file:

orig: 604x299pixels (Doc size: 6.04in x 2.99in) @ 100dpi
mine: 604x299pixels (Doc size: 8.389in x 4.153in) @ 72dpi
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color substitutions

Post by snibgo »

Hooray!

Code: Select all

convert ... compress Lossless x.jpg
... may work for you, giving a jpeg that doesn't mangle colours. (It works for me, IM 6.8.9-5 on Windows 8.1)

When you have the right number of pixels, you can set the density to anything you like, such as "-density 100 -units pixelsperinch".
snibgo's IM pages: im.snibgo.com
stevenb46
Posts: 40
Joined: 2014-08-20T08:47:18-07:00
Authentication code: 6789

Re: Color substitutions

Post by stevenb46 »

convert "c:\eps\im\g51n34.eps" -antialias -quality 100 "c:\eps\im\g51n34a.png"
convert -density 1000 -colorspace sRGB "c:\eps\im\g51n34a.png" -fill "rgb(255,131,0)" -units pixelsperinch -compress lossless -opaque "rgb(255,103,0)" -quality 100 "c:\eps\im\g51n34.jpg"

This doesn't seem to work? Getting the same result. I set density to 1000 to improve clarity of the jpg.
Post Reply