Answers.Body: <p>PNG and DjVu are <a href="http://djvu.sourceforge.net/index.html#inside" rel="nofollow">complementary</a> formats as PNG is lossless and DjVu is lossy. DjVu's effectiveness in storing information is the result of using high quality compression and <strong>splitting</strong> a single image into multiple layers which essentially employ different compression algorithms.</p>
  
  <p>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 <strong>they don't generate the same output</strong> (in quality and compression).</p>
  
  <p>Hazzit's answer is correct for monochrome images, as it first converts the PNG to a bitonal (black &amp; white) image that is then, using <code>cjb2</code>, stored in the bitonal layer of a DjVu file. With the <code>--clean</code> option <code>cjb2</code> 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.</p>
  
  <p>Low color PNG images can be converted first to <code>.ppm</code> (you can do this with the ImageMagick as in Hazzit's answer as well by specifying a <code>.ppm</code> output file name instead of a <code>.pbm</code>) and then use <code>cpaldjvu</code>. This program does simple quantization, and stores this information into multiple layers.</p>
  
  <p>If your PNG has many colors (like in a photo) you will have better results converting the PNG file to JPEG (again with <code>convert</code> and a <code>.jpg</code> 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 <code>pdf2djvu</code> 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.</p>
  
  <p>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 <strong>do not help you determine what compression is best for the image</strong> you provide. You implicitly do that by selecting the conversion program (<code>cjb2</code>, <code>cpaldjvu</code> etc).</p>
  
  <p>In my experience the DjVuLibre&mdash;as a reference implementation&mdash;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 <code>any2djvu</code> 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 <a href="http://caminova-inc.software.informer.com/" rel="nofollow">Caminova</a> and now possible from <a href="https://www.cuminas.jp/en/" rel="nofollow">Cuminas</a> </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-02-18T16:07:06.740Z
Answers.Text: Thanks for your comprehensive answer. I'll try your method.
Answers.UserDisplayName: hans-t
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-02-17T06:10:18.273Z
Answers.LastActivityDate: 2016-07-09T10:36:23.153Z
Answers.LastEditDate: 2016-07-09T10:36:23.153Z
Answers.UserDisplayName: Anthon
Answers.Body: <p>There is a <a href="http://commons.wikimedia.org/wiki/Help:Creating_a_DjVu_file#Converting_page_scans" rel="nofollow noreferrer">Wikipedia help page</a> on that subject. Apart from <a href="http://djvu.sourceforge.net/" rel="nofollow noreferrer">DjVuLibre</a> you will need <a href="https://imagemagick.org/script/download.php" rel="nofollow noreferrer">ImageMagick</a></p>
  <p>Step 1: Convert PNG to PBM using ImageMagick's <code>convert</code> utility:</p>
  <pre><code>convert myfile.png tempfile.pbm
  </code></pre>
  <p>Step 2: Convert PBM to DJVU using DjVuLibre's <code>cjb2</code> utility:</p>
  <pre><code>cjb2 -clean tempfile.pbm myfile.djvu
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-02-18T16:06:03.783Z
Answers.Text: The method is difficult, as you must convert the image one by one.
Answers.UserDisplayName: hans-t
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-02-19T03:26:52.777Z
Answers.Text: @user74158 Batch files do exist.
Answers.UserDisplayName: Hazzit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2014-02-16T23:33:15.337Z
Answers.LastActivityDate: 2020-12-02T18:30:59.057Z
Answers.LastEditDate: 2020-12-02T18:30:59.057Z
Answers.UserDisplayName: Hazzit
Answers.Body: <p>An interesting option is Jakub Wilk's <a href="http://jwilk.net/software/didjvu" rel="nofollow">didjvu</a>, but it is not available on Windows. I don't think the program contains anything Linux specific, just the author doesn't use Windows. Perhaps a user will port it to Windows, as it happened with <a href="http://jwilk.net/software/pdf2djvu" rel="nofollow">pdf2djvu</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-12T07:30:25.957Z
Answers.LastActivityDate: 2014-10-12T07:30:25.957Z
Answers.UserDisplayName: Janusz S. Bień
Body: <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-02-16T15:31:08.240Z
Comments.Text: Which operating system (it may affect the answers)?
Comments.UserDisplayName: Jason Down
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-02-16T15:36:22.353Z
Comments.Text: I'm using windows 8.1.
Comments.UserDisplayName: hans-t
Tags: <djvu><windows>
Title: Convert PNG to DJVU
UserDisplayName: hans-t
ThreadText: # Convert PNG to DJVU
  
  (Asked by: username_0 on 2014-02-16)
  
  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.
  
  **Tags:** djvu, windows
  
  > **Comments:**
  > **username_1**: Which operating system (it may affect the answers)?  
  > **username_0**: I'm using windows 8.1.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2014-02-17. Score: 5 | Accepted answer
  
  PNG and DjVu are [complementary](http://djvu.sourceforge.net/index.html#inside) 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).
  
  username_3'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 username_3'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](http://caminova-inc.software.informer.com/) and now possible from [Cuminas](https://www.cuminas.jp/en/)
  
  > **Comments:**
  > **username_0**: Thanks for your comprehensive answer. I'll try your method.  
  
  ---
  
  ### Answer by username_3 on 2014-02-16. Score: 1
  
  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
  
  > **Comments:**
  > **username_0**: The method is difficult, as you must convert the image one by one.  
  > **username_3**: @user74158 Batch files do exist.  
  
  ---
  
  ### Answer by username_4 on 2014-10-12. Score: 0
  
  An interesting option is Jakub Wilk's [didjvu](http://jwilk.net/software/didjvu), but it is not available on Windows. I don't think the program contains anything Linux specific, just the author doesn't use Windows. Perhaps a user will port it to Windows, as it happened with [pdf2djvu](http://jwilk.net/software/pdf2djvu).
  
  
  ---
  
  