8

I have a .ppm file which is colored and when I am running Potrace:

potrace -s file.ppm

It returns only a white and black .svg file. If I do it on inkspace it keeps the colors.

If it helps this is the xxd | head of the .ppm file:

$ xxd file.ppm | head
00000000: 5036 0a31 3030 3020 3130 3030 0a32 3535  P6.1000 1000.255
00000010: 0add dddd bbbb bbbb bbbb bbbb bbbb bbbb  ................
00000020: bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb  ................
00000030: 7900 bb89 2fbb bbbb bbbb bbbb bbbb bbbb  y.../...........
00000040: bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb  ................
00000050: bbbb bbbb bbbb bbbb bbbb bbbb 8787 872e  ................
00000060: 2e2e 2b2b 2b3b 3b3b 4545 453d 3d3d 4545  ..+++;;;EEE===EE
00000070: 4550 5050 7f7f 7fbb bbbb bbbb bbbb bbbb  EPPP............
00000080: bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb  ................
00000090: bbbb bbbb bbb1 b1b1 8181 8164 6464 7575  ...........ddduu

If not how could we use Inkscape via the command line.

0x90
  • 322
  • I recommend pre-separating the image into a few colors, and then tracing each one separately. It won't be very pretty, but it might give you something. – TheLabCat Oct 29 '23 at 18:12

1 Answers1

8

You can’t.

Potrace strictly processes any/all import to black and white output.

According to the official FAQ, there is no support for color output; strictly black and white output:

Question: Can Potrace handle color images?

Answer: The short answer is "no". Potrace can only handle 2-valued images at the moment. It does not matter whether the two colors are called "black" and "white" or "on" and "off" - however, there can be only two of them.

Question: Will color support be added to Potrace in the future?

Answer: Maybe.

That said, the FAQ mentions Inkscape and states that it uses the core Potrace engine and retain color via color quantization:

Recent versions of Inkscape have a built-in Potrace engine that can handle color images via color quantization or multiple scanning, thanks to the great work of Bob Jamison and the Inkscape team.

While I am not deeply familiar with how Inkscape works, but a quick search through the official Inkscape wiki explains “Shell mode” as follows:

To open and edit multiple files after one another without opening a new Inkscape instance for each file, Inkscape offers the shell mode. This mode uses your computer's resources more efficiently, and allows for faster batch processing. The commands are largely identical to those for the 'normal' mode.

You can launch the interactive command line with inkscape --shell.

The main difference to commands in the normal mode is that you need to explicitly indicate when you want to open a file, e.g. file-open:filename.svg; select:flowRootID; query-height.

Giacomo1968
  • 55,001