A következő címkéjű bejegyzések mutatása: ImageMagick. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: ImageMagick. Összes bejegyzés megjelenítése

2019. január 3.

ImageMagick not authorized format conversion

For the following command
convert example.pbm example.ps
I got the following error:
convert: not authorized `example.ps' @ error/constitute.c/WriteImage/1028.
I fixed it by following the instructions in this post:
  1. sudo gedit /etc/ImageMagick-6/policy.xml
  2. change 'rights' from "none" to "read|write" in the line where the 'pattern' is 'PS'.
    I changed it for 'PDF' too and moved these lines to a separate section, so now it looks like this:
  <!-- manually re-enabled ghostscript format types -->
  <policy domain="coder" rights="read|write" pattern="PS" />
  <policy domain="coder" rights="read|write" pattern="PDF" />

2015. április 30.

color to grayscale PDF

The source file:
a PDF with page size US letter portrait
with text layer (different color and text background varying)
with color images as background (many images sum up to one background picture

The quest: convert the source PDF to:
a PDF with page size A4 portrait
with or without text layer (flatten or not - but keep text readable)
with grayscale and/or black and white (but recognizable) images as background

The purpose: print out the pdf on a regular black-and white printer:
keep it readable, and esthetically enjoyable
do not use more ink than necessary

***
The routes I tried:

1.) (from under the text layer) extract images, convert images, put images back.

Toolkit:

Extract images:
pdf2htmlEX --embed cfijo example.pdf

Convert images:
mogrify -type Grayscale -format ps *.png

...convert back to pdf with ps2pdf, join with pdfjoin or pdftk

Extract text layer:  
cpdf -draft example.pdf -o example_text.pdf

Put background images behind text layer:
pdftk  example_text.pdf multibackground example_images.pdf output modified.pdf


2.) flatten PDF to images, edit images.

Toolkit:

Burst pdf to single pages:
pdftk example.pdf burst

Convert to PostScript:
pdftops (and not pdf2ps)

Flatten ps to pnm and edit image
mogrify -format pnm -density 200x200 -type grayscale *.ps

...convert back to pdf with ps2pdf, join with pdfjoin or pdftk



***
In the end I chose the second route, because I had some trouble with the fonts in the pdf, which were not exported properly, and left a black text box in the images (making the text unreadable after backgrounding back to pdf)

Also the first route would involve a lot of learning of the PDF structure, the layer manipulation, and so on.

2014. március 16.

DJVU extract images

A useful link:
http://askubuntu.com/questions/46233/converting-djvu-to-pdf

Another useful link: http://unix.stackexchange.com/questions/20592/extract-several-pages-from-a-djvu-file
http://kheyali.blogspot.hu/2011/08/in-order-to-convert-djvu-file-into.html

And another: http://en.wikisource.org/wiki/Help:DjVu_files#DjVu_to_Images


Extract images from DJVU:
DDJVU
The easiest way to do this is probably by extracting to multipage tiff
Than split tiff file with tiffsplit: http://manpages.ubuntu.com/manpages/hardy/man1/tiffsplit.1.html
Than convert to anything useful.
Except that did not work for the file I had...

Okay, so the second way is the script way. Copy the script, paste it to an empty text file. Give it the extension .sh and give it permission to execute as program. Put it in a directory with all the djvu-s you want to extract and run in terminal.

#!/bin/bash
#Ubuntu 10.04 Lucid Lynx

#Put this script file in a directory with all the djvu-s you want to extract and run it in terminal.
#All the DJVU-s in this folder will be extracted to PNM-s.

### Select files to process
#defining the filelist
filelist=(`find -iname '*.djvu' | sort`)
#counting the files in the filelist
element_count=${#filelist[*]}
echo "alltogether $element_count djvu will be processed"

#process only 1 file at a time:
counter=1
echo "processing file:"
for i in "${filelist[@]}"
do
echo -ne "$element_count/$counter"\\r

#Get the number of pages from input file
pagecount=`djvused -e n $i`
#Set a filelist for the pages
 for (( filelist=1; filelist<=$pagecount; filelist+=1 ))
 do
 #Extract with DDJVU
 ddjvu -format=pnm -page=$filelist $i file_$counter.page_$filelist.pnm
 #Or use DjvuPs to extract PS from DJVU the same way:
 #djvups -page=$filelist $i file_$counter.page_$filelist.ps
 done
let "counter = $counter + 1"
done

echo DONE.

2014. február 19.

Modify PDF pages as images, than reintegrate

what just has happened?!

I successfully reintegrated a modified PDF in the original file!

wow! that is definitely a level up in image-pdf editing for me.

pdftk input.pdf cat 2 output page2.pdf
pdfinfo page2.pdf 
Page size: 595 x 842 pts (A4) pdfimages page2.pdf img
identify -verbose img-000.pbm
Geometry: 2496x3440+0+0 Resolution: 72x72 Page geometry: 2496x3440+0+0 Modified the image through Gimp. Open, Edit, Save -> Export -> click Ok whenever needed. convert img-000.pbm -resample 300x300 -resize 2496x3440 img2.ps
identify -verbose img2.ps
  Geometry: 599x826+0+0
  Resolution: 72x72
  Page geometry: 599x826+0+0

ps2pdf12 -sPAPERSIZE=a4 -dFIXEDRESOLUTION img2.ps page2_v2.pdf
pdfinfo page2test4pdf.pdf 
  Page size:      595 x 842 pts (A4)

pdftk A=input.pdf B=page2_V2.pdf cat A1 B A3-end output output.pdf

2012. december 29.

Small size Color PDF

After years of struggling with color PDF-s, I realized today that color PS exists, which lead to a fast solution on the given problem.

Here's how it goes:

  1. GSCAN2PDF
    scan image
    on 8-bit depth and 300 dpi resolution.
    save in PNM file format.
    this results in an approx. 20MB size file.
  2. CONVERT
    resize
    to 50%
    convert bigimg.pnm -resize 50% smallimg.pnm
    file size abt. 5MB
  3. PNMTOPS
    convert to ps
    pnmtops -equalpixels smallimg.pnm > smallimg.ps
    file size abt. 10MB
  4. PS2PDF
    convert to pdf
    ps2pdf12 smallimg.ps smallimg.pdf
    */Sadly, I could not manage to have the pdf cropped to the proper size with ps2pdf, so I have to do it manually in the next step. However if You know the solution to this problem do not hold back on sharing it with me!/*
    file size abt. 200KB
  5. PDFCROP
    crop pdf of unnecessary margin
    pdfcrop smallimg.pdf
    (resulting in smallimg-crop.pdf)
    final file size abt. 200KB
This is how you do a good quality color pdf from good quality large images.

...And a couple months later (19 May 2013) I realized that my method of producing black-and-white pdfs, which I use since years, is just as good to produce color pdfs as the above or even better because with the old method I do not have to use pdfcrop, ad the pdf page size of the color cover will be compatible with the b&w pages...

2012. augusztus 26.

Watermarking PDF-s

Program used:
PDFTK (get from Synaptic)
* Apply a Background Watermark or a Foreground Stamp

Method:


pdftk [input filename="filename" pdf="pdf" ] stamp [stamp filename="filename" pdf="pdf"] output [output filename="filename"]

What happens?

I made a transparent background GIF with GIMP, converted it to pdf, with Mogrify, and applied it to the pdf.

Application of a different size watermark image than the original pdf page happens with scaling the watermark image to fit the height and with keeping the watermark's size ratio, and fitting it in the center of the original page.

2012. június 28.

Scanned Image Color Correction

Seems like using -contrast-stretch 1x10% in ImageMagick's convert is useful after scanning color image bit depth 8 density 300 with gscan2pdf and Canon LiDE 210.

2010. november 14.

ImageMagick BMP compression

To make uncompressed BMP files, or to decompress BMP files in ImageMagick, use the -compress none option.

To make less then 24-bit BMP files in ImageMagick, use the -colors 256 option, which would make a 8-bit BMP file.

Use these settings to be able to import scores into Neuratron PhotoScore.

2010. november 13.

image to pdf

I really can't handle ImageMagick when it comes to pdf files. It creates such huge files they are completely useless.

I tried out another way: pbm -> ps -> pdf:

first I ImageMagick convert pbm-s:
mogrify -format ps -density 300x300 *.pbm
then put them into ps2pdf:
#!/bin/bash
lista=(`find -iname '*.ps' | sort`)
for i in "${lista[@]}"
do
ps2pdf -r300 -g1880x2688 $i $i.pdf
done

and bind them:
pdfjoin *.pdf --outfile output.pdf

It worked brilliantly. This way my pdf is 8 times smaller then my original pdf, and it's only 1.5 times bigger then the djvu I made from the same images.

Djvu was made directly from pbm files, converted with cjb2 and binded with djvm. No special option was used.

2010. november 7.

Image INFO through ImageMagick

identify -verbose image.jpg

To get only what you want to see you can use GREP like this:

identify -verbose image.ps | egrep "Resolution|Geometry"

This will return you the lines with Resolution and Geometry. Just what I need to make good compressed pdf files with ps2pdf.

2010. október 27.

Working in Imagemagick

Clearing margin area

I'm working on a scanned text page, that needs a cleanup on the margins.
the original image size is 2736x3928 and it's a pbm file.
~$ convert orig.pbm -crop 2320x3928+120+0 crop.pbm
this cuts down 120 pixels from the left side, and 2736-120-2320=296 pixels from the right side.
~$ convert crop.pbm -bordercolor white -border 296x0 -gravity none -crop 2736x3928+176+0 back.pbm
this puts back the cut-down border in the color white. (first we add a 296 pixel wide border to both sides, which makes our image 296+296+2320=2912 wide. we only need the 296 border on the right side, so we crop the one on the left to be 120 px with 296-120=176 pixels. check: 2912-176=2736 we counted right.)

You have to do this 2 step separately. You can use mogrify instead of convert to edit multiple files, but ALWAYS make a backup copy of your files before using mogrify!

That's it. Enjoy.

2010. március 7.

Image rotation nautilus script in the right click menu

create folder:
/home/user/.gnome2/nautilus-script

create files:
"Rotate CW"
"Rotate CCW"
"Rotate 180"

edit these in gedit, and than make them executable.

This is the script for Rotate CW:
#!/bin/bash
mogrify -rotate 90 $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
for CCW use 270 and for 180 use 180 instead of 90.

2009. január 3.

ImageMagick converting multiple files

*I do not use this method anymore, although it was a great start.*

After being a book-worm for half a day, I found out how can I write a working script to solve my imagemagick output problem.
It looks like this:


#!/bin/sh

for i in `find -iname '*.jpg'`
do
convert $i -background white -flatten -colorspace Gray -negate -edge 1 -negate -normalize -sharpen 1 -threshold 50% -despeckle -blur 0x.5 -normalize +dither -posterize 8 gif:- >> $i.gif
done
1.) open your favorite text editor
2.) copy paste the script
3.) save as anyname.sh
4.) make it executable

Usage:
1.) copy anyname.sh in the folder containing only the image files you want to make simple
2.) go (cd) to this folder in the terminal
3.) type ./anyname.sh
4.) wait and see.

How to convert this to pdf?

mogrify -format pdf *.JPG

How to join these single-page pdfs?

pdfjoin *.pdf --outfile newname.pdf