how to correct the dpi in a scanned file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
cts

Re: how to correct the dpi in a scanned file

Post by cts »

I can only try to help you if you have a problem with an image that you want to solve with ImageMagick.
I can't really help you if you have problems in the handling of your scanning and printing software.
I see now that my problem is with scanimage(1), not imagemagick. Thank you for your help.
Well, maybe you should try to save your scanned images (in 'scanimage') in a 'better' format right at the start. (A format that can store the correct density, e.g. TIFF, PNG, BMP etc. - not PNM.) That would minimise your problem.
This is another interesting point. I've googled and googled, but everybody who addresses this issue is dealing with TIFF. Now, I've been using this set up for years, scanimage(1), lpr(1), and PNM (it used to work for me), and I think TIFF is a microsoft format, so I thought that I should be able to continue using PNM, but maybe PNM has problems storing the density? Is TIFF just as good as PNM? Are there disadvantages to it?

...
Anyway - regarding your problem with the correct density value in the PNG file: That should be solved.

cts wrote:What I really need is the command to force the file to have the real density


You did that.
What I think I did was to convert a file of density 300 by a factor of 300/72, yielding an effective density of 1250 dpi. I suspect that lpr did the same thing when I passed it a file with an improperly given density 72.

But thank you for your suggestion of posting the file - as soon as I find a good place to do so, I'll try that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to correct the dpi in a scanned file

Post by anthony »

dropbox lets you put files on the web (no need for their application. However their application lets you have a directory to simply copy the file in and out. The posted files can be made public.
This is what I now do for image I post to the forum.

dropio lets you create a random drop folder (you don't even need to register). Its even simplier.
though less permanent, and less control. Lots of other places too.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cts

Re: how to correct the dpi in a scanned file

Post by cts »

My statement:
Now, I've been using this set up for years, scanimage(1), lpr(1), and PNM (it used to work for me),
got me to wondering ... if that was so, then what am I doing here? Then I remembered: normally, I go to pdf:

convert -page A4 test.pnm test.pdf

does exactly the right thing! That output document fits nicely on my screen and on my printer. But the same command:

convert -page A4 test.pnm test.png

doesn't change the size! That's the reason that I've been pursuing this so long. It's hard to believe that some imagemagick commands get it right and others don't...
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: how to correct the dpi in a scanned file

Post by Drarakel »

There are settings that are different for different formats. And PDF is a completely different animal anyway.
Your PNM has no density value. But if you specify "-page A4" for PDF, IM knows the real-world size and can write a correct MediaBox value. A PDF has no fixed density - but usually only such box values (with a size in points @ 72dpi). And after that, a viewer or printing program has to decide at which density it displays/prints the PDF.
Instead of:
convert -page A4 test.pnm test.pdf
You could also use that (if the dimensions fit to a A4 page at 300dpi):
convert -units PixelsPerInch test.pnm -density 300 test.pdf
(With that, IM also knows how to convert the values for dimensions and density to a correct size for PDF.)
If you want to know more about PDF:
http://www.imagemagick.org/Usage/formats/#pdf

And if you want to correct the density value for an image (not PDF), use the mentioned command line:
convert -units PixelsPerInch test.pnm -density 300 test.png
You will have a correct PNG file. But you must tell your printing program to actually print at 300dpi (if the density inside the file isn't used).

Of course, you could also downsize the image - if you just want to print at 72dpi:
convert -units PixelsPerInch test.pnm -density 300 -resample 72 test.png
But this lowers the dimensions / the quality.
Post Reply