How can I convert PNG to DjVu? I only know how to convert JPEG or PPM to DjVu using DjVuLibre. I'm using Windows 8.1.
3 Answers
PNG and DjVu are complementary formats as PNG is lossless and DjVu is lossy. DjVu's effectiveness in storing information is the result of using high quality compression and splitting a single image into multiple layers which essentially employ different compression algorithms.
As you indicate, you already know how to convert JPEG or PPM to DjVu, so the simple answer is convert your PNG to either JPEG or PPM and use that as an input for you known conversion. These can be considered different routes to obtaining a DjVu file because they store data in different layers, and they don't generate the same output (in quality and compression).
Hazzit's answer is correct for monochrome images, as it first converts the PNG to a bitonal (black & white) image that is then, using cjb2
, stored in the bitonal layer of a DjVu file. With the --clean
option cjb2
does only minimal lossy compression, but if you start out with a multicolor PNG (such as a photo), you will have lost most of the information in the conversion to a bitonal image.
Low color PNG images can be converted first to .ppm
(you can do this with the ImageMagick as in Hazzit's answer as well by specifying a .ppm
output file name instead of a .pbm
) and then use cpaldjvu
. This program does simple quantization, and stores this information into multiple layers.
If your PNG has many colors (like in a photo) you will have better results converting the PNG file to JPEG (again with convert
and a .jpg
output file) and then use that to convert to DjVu. You can e.g. print/convert the PNG to PostScript and use that as input to pdf2djvu
that is part of DjVuLibre. The resulting image data is compressed using Wavelet compression and stored in a different layer from the bitonal one mentioned in the previous example.
What route to take depends on the contents of the input file format and the required result, far more than it does on being a PNG file. Especially with the DjVuLibre tools no boilerplate answer can be given, as they do not help you determine what compression is best for the image you provide. You implicitly do that by selecting the conversion program (cjb2
, cpaldjvu
etc).
In my experience the DjVuLibre—as a reference implementation—generates correct DjVu files, but it doesn't employ the best compression techniques to generate the output. You might want to look at a converter that is not based on DjVuLibre, if resulting compression ratio and/or image quality is important. You can use any2djvu
to do an online conversion, or one of the other online conversion tools. They do a better analysis of the images to determine what is the best way to compress your image (i.e. what goes in what layer). You can freely experiment with those, but of course you don't know what happens with your data. The commercial Document Express Editor also does a better job, (originally from LizardTech, who also released the DjVuLibre as open source), which was for some time available from Caminova and now possible from Cuminas
There is a Wikipedia help page on that subject. Apart from DjVuLibre you will need ImageMagick
Step 1: Convert PNG to PBM using ImageMagick's convert
utility:
convert myfile.png tempfile.pbm
Step 2: Convert PBM to DJVU using DjVuLibre's cjb2
utility:
cjb2 -clean tempfile.pbm myfile.djvu
-
-
1