Page 1 of 1

Convert image and mask to PNG

Posted: 2014-12-17T15:09:21-07:00
by oceanthrsty
I have an image
Image

And it's mask
Image

Here's the command I'm using right now:

Code: Select all

convert main.jpg \( mask.jpg -colorspace gray -alpha off \) \ -compose  copy-opacity -composite new.png
It produces a great PNG... but it's in grayscale :(

How can I get it in color.... and is there anyway to make it process faster?

Thanks!

Re: Convert image and mask to PNG

Posted: 2014-12-17T15:23:53-07:00
by snibgo
It works fine for me, IM v6.9.0-9, red letters on a transparent background.

What version IM are you using? Perhaps an old one, and you need to upgrade.

You don't need "-colorspace gray -alpha off".

Using miff instead of jpg for input may be faster. Png is slow to write; one of the compression options may make it faster.

Re: Convert image and mask to PNG

Posted: 2014-12-17T19:54:40-07:00
by oceanthrsty
What's the exact syntax you're using?

I upgraded my version I'm running the same syntax as above and I'm getting an error message

Code: Select all

convert main.jpg \( mask.jpg -colorspace gray -alpha off \) \ -compose  copy-opacity -composite new.png

convert: unable to open image ` -compose': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to open image `copy-opacity': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
I get a new.png exported. But it looks exactly like the mask.jpg :?

Thanks

Re: Convert image and mask to PNG

Posted: 2014-12-17T20:27:34-07:00
by snibgo
oceanthrsty wrote:I upgraded my version
What version are you now using? "convert -version"

My commands (Windows BAT syntax):

Code: Select all

%IM%convert ^
  -verbose ^
  main.jpg ^
  ( mask.jpg -colorspace gray -alpha off ) ^
  -compose copy-opacity -composite ^
  new.png

%IM%convert ^
  -verbose ^
  main.jpg ^
  mask.jpg ^
  -compose copy-opacity -composite ^
  new2.png

%IM%convert main.jpg main.miff
%IM%convert mask.jpg mask.miff

%IM%convert ^
  -verbose ^
  main.miff ^
  mask.miff ^
  -compose copy-opacity -composite ^
  new3.png
All three results have red letters on transparent background.

Re: Convert image and mask to PNG

Posted: 2014-12-17T21:02:23-07:00
by fmw42
try breaking the line at the \ or remove it. You cannot have a space after a new line \. Also add -alpha off before -compose

Code: Select all

convert main.jpg mask.jpg \
-alpha off -compose  copy-opacity -composite new.png
or

Code: Select all

convert main.jpg  mask.jpg -alpha off -compose  copy-opacity -composite new.png

If on Windows, the new line character is ^ rather than \. Also Windows does not need to escape the parenthesis and escape is ^. I assume above that you are not on Windows.

Re: Convert image and mask to PNG

Posted: 2014-12-17T21:30:35-07:00
by snibgo
Well spotted, Fred. The OP's command seems to be a single line with a spurious backslash, like this (bash syntax):

Code: Select all

$ convert xc: xc: \ -composite x.png
convert: unable to open image ` -composite': No such file or directory @ error/blob.c/OpenBlob/2709.

Re: Convert image and mask to PNG

Posted: 2014-12-18T08:44:26-07:00
by oceanthrsty
Fred,

Thank you. That works!