[RESOLVED] Background color not applied in conversion from EPS to JPEG

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kriks
Posts: 114
Joined: 2008-01-04T05:52:03-07:00

[RESOLVED] Background color not applied in conversion from EPS to JPEG

Post by kriks »

Hi all,

given a EPS with a named clip path, I want to convert it into a JPEG with the clip area colored (from background-color).

I use IM 6.9.0-3 and GS 9.15

Here is the EPS : http://kriks.free.fr/IM/ball/ballon_foot.eps
Here is my command-line (I tried various placements of the background parameter):

Code: Select all

convert -verbose -units PixelsPerInch -density 100 'ballon_foot.eps[0]' +repage -auto-orient -resize 500x500 -colorspace 'sRGB' -alpha transparent -clip-path 'det' -alpha opaque -background red -flatten 'JPEG:ballon.jpg'
This will result in a black background around the ball : http://kriks.free.fr/IM/ball/ballon.jpg

Outputing as PNG then piping into convert to get a JPEG with the background-color works (but it would reduce the case to RGB images):

Code: Select all

convert -verbose -units PixelsPerInch -density 100 'ballon_foot.eps[0]' +repage -auto-orient -resize 500x500 -colorspace 'sRGB' -alpha transparent -clip-path 'det' -alpha opaque PNG32:- | convert PNG32:- -background red -flatten 'JPEG:ballonByPng.jpg'
http://kriks.free.fr/IM/ball/ballonByPng.jpg

Am I wrong with my use of Imagemagick or is there a bug somewhere ?
Last edited by kriks on 2015-02-18T02:20:39-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Background color not applied in conversion from EPS to JPEG

Post by snibgo »

Your first command has "-alpha opaque -background red -flatten". This makes pixels opaque, so "-flatten" will do nothing, so "-background red" does nothing.

This does what I think you want:

Code: Select all

%IM%convert ^
  -verbose -units PixelsPerInch -density 100 ballon_foot.eps[0] ^
  -colorspace sRGB ^
  -alpha transparent -clip -alpha opaque +clip ^
  -background red -flatten ^
  -resize 500x500 ^
  x1.jpg
Windows BAT syntax, so adjust as required.

I convert to sRGB early, but I leave the resize to the end to get a cleaner transition to the background.

"-alpha transparent -clip -alpha opaque +clip" makes the entire image transparent, then turns the clip area opaque. Then "-background red -flatten" turns the tansparent area red.
snibgo's IM pages: im.snibgo.com
kriks
Posts: 114
Joined: 2008-01-04T05:52:03-07:00

Re: Background color not applied in conversion from EPS to JPEG

Post by kriks »

Thank you very much !

The part that was missing was "+clip" to deactivate the clip path for the next operations.
And the resize tip is also great :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: [RESOLVED] Background color not applied in conversion from EPS to JPEG

Post by snibgo »

Yes, -clip almost always needs +clip, like a bracketing pair.
snibgo's IM pages: im.snibgo.com
Post Reply