Shell exercices

Wanna convert a pdf to images and create a gallery. Well, I had some actions with that and I did my way through the GNU, and other, utilities.

1. First
You need to convert the PDF document to images. Not so easy, there is pdftohtml but it doesn't generate images, instead it extracts the text and images from the document. However there is ImageMagick, a great project, which provides convert. So I ran a convert file.pdf file.png but I couldn't figure out how to preselect the size to get bigger resolutions. After that I have opened file.pdf with xpdf and I took screenshots with scrot from the xpdf window.

2. Crop images
I cropped the images to remove the borders and toolbars with for image in *.png ; do convert $image -crop 150x150+30+20 ; done where I selected the geometry of the crop size in GIMP within the dialog of the crop tool.

3. Rename files
Next I figured out how to rename files, and how to bulk rename (Thunar -B) them better.

4. Finally
I have found photon --thumbsize=50x50 --sizelist=0 -o photon ../images which creates nice web galleries. With javascript, you can view the presentation as in a pdf reader, by pressing space to switch pages.

However there is a bug, fortunately this blog entry will remember me to file it upstream. My images are png files, and it creates jpeg files. The original files are copied verbatim without modifications, but the html files contains source images only with .jpg extensions. Bad, because I have png files...

5. A last one before to go
for html in *.html ; do cat $html | sed -r 's,(original)/([0-9]+)-(projet-tuteure)\.jpg,\1/\2-\3.png,' > $html ; done


You can see the result of photon if you are interested.

Edit: Just in case I forget about it and would need it again... photon --thumbsize=105x105 --display-lines=4 --sizelist=0 --resize-quality-low=95 --img-bgcolor=#ffffff --body-bgcolor=#2e3436 -k steel -o photon ../images && cd photon && for html in *.html ; do cat $html | sed -r 's,(original)/([0-9]+)-(projet-tuteure)\.jpg,\1/\2-\3.png,' > $html ; done && cd ..

No comments:

Post a Comment