Question

I have a few black and white djvu files that I would like to add a few different background images to at random. This is to make it seem more book like and I think looks better.

Using the command line I can extract each image and then write some code to add the background however this bloats the file a lot because of duplication. I would like to add the background to the file once and then include it using the INCL chunk for the other pages. However it is very confusing how to do this through the DjvuLibre command set.

The current djvu file also has a text layer that I would like to extract and then reapply.

Was it helpful?

Solution

I wrote some code to automate the steps here.

Which are listed below:

In order to successfully add a background image to a foreground image, I have to follow these steps (using a DOS Cmd window):

1- extract the bitomal RLE image from the Djvu File

ddjvu -format=rle -v myfile.djvu temp.rle

2- extract (or create) the background image. Be sure that the size of this image is equal or greater than the foreground image in order to have, after a reduction a integer:

e.g. I have a 2592 x 3508 300dpi foreground image, and I want a background image of 100dpi. So I create a 2592] x 3510 100dpi image (I added 2 pixels to the height in order to have 2594 modulo 3=0). After a 1/3 resampling, I have a 864 x 1170 image.

3- (do something with this background image) and save it as myfile.ppm (24 bits per pixel)

4- join into an unique file the 2 images:

copy /b myfile.rle + myfile.ppm myfile.mix (using a brave old DOS command)

5- encode the new page into a DjVu file:

csepdjvu -vv -d 300 myfile.mix myNewFile.DjVu

Bingo: It works!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top