changing DPI of an image?

BlitzMax Forums/BlitzMax Programming/changing DPI of an image?

gameproducer(Posted 2011) [#1]
I'm working on to get my Pixmap to png working (here http://blitzbasic.com/Community/posts.php?topic=94614 ) and there's one part that's missing:

Currently I save pixmaps as pngs like here:
SavePixmapPNG(img, "../mydeck/processed/" + filename, compression)


This goes fine, and images have DPI 72. There's plenty of pixels but I'd need to make it better quality for printing (and to get correct print size, with dpi 72 my cards would be heckofa wide :D), thus I'd need to change DPI to 300 or 400.

Any ideas on changing DPI. Ideally I'd prefer:

1) Setting DPI while saving the image / Processing DPIs after saving using bmax. (Ideally, user should be able to define the new DPI)

Or

2) Buy/get some non-bmax software that does this (but would be good that licence would allow sharing, otherwise it's not much use to me)

I'd prefer #1. :)

EDIT: Also, should work with PNG files. JPG is a optional bonus.

Last edited 2011

Last edited 2011


GfK(Posted 2011) [#2]
Maybe Irfanview?


AdamRedwoods(Posted 2011) [#3]
DPI = dots per inch.

so whats the ratio from 72dpi increased to 300dpi? (4.16666)
Then your new size will be the current card size * that ratio.

Once you have your new size, just use ResizePixmap().
If you need a better resize algorithm, then you'll need Photoshop caliber.


gameproducer(Posted 2011) [#4]
@GfK: checking it out - if it can do batches, easily (so that preferrably user doesn't need to do anything but click once), then it might be ok.

@Adam:
To clarify: I mean DPI for printing. For example, I can have image that is 1000 pixels wide. If image has 100 dpi, then print version would be 10 inches wide (100 pixels per inch).

with 300 dpi, the pixels would be read by the printer so that the print version would be 3,33 inch wide.

If I'd do ResizePixmap, then it would mean that I'd get poorer quality since the printed product width is always the same 3 inches or so. In ResizePixmap the card pixels would be 4.16666 times smaller, and then with 72 dpi the print I could get 3 inch wide product.

Increasing pixmap 4.16666 bigger would give me 12 inch+ wide card. :)

I got pixels fine (1050 x 1450), I just need to change the DPI for printing purposes.

(Adam - correct me if I'm wrong, or misunderstood what you meant)


AdamRedwoods(Posted 2011) [#5]
You're correct.

card = 1000 pixels width in current pixmap
printer = 10 inches wide @ 300dpi

therefore new width of ResizePixmap @ 300dpi = 3000 pixels


As for quality, ResizePixmap (i believe) uses a bicubic formula, so it will basically blur the image.

but I don't know of too many software programs that would do any better for enlarging something that size (there is one that uses fractals). You'll have to test it to see if it's an acceptable quality. Sometimes it's ok. Otherwise you'll have to look into using vector images, which leads me back to Brucey's Cairo modules. Vector images are DPI independent.

Last edited 2011


gameproducer(Posted 2011) [#6]
I'm quite new to dpi (trying to learn about it this day :D) but I believe it's not so much about increasing pixels... if I just could somehow tell image to be "300 dpi instead of 72", I'd be fine.

Since... the amount of pixels is fine (1050 x 1450 in my case). What I need is to change DPI info in pic so the printhouse can process it properly.

[infranview]
checked it... too much options for my taste.


xlsior(Posted 2011) [#7]
You can change the DPI (and leave the pixel dimensions alone) using ImageMagick: http://www.imagemagick.org

Imagemagick comes with a command line tool, 'convert.exe' that can do many things, including change the DPI:


convert.exe input.jpg -density 180 output.jpg




ima747(Posted 2011) [#8]
[edit] sorry, was thinking of Brucy's FreeImage module... don't know if it supports DPI control

To clarify, DPI is a print conversion value basically, it doesn't affect the actual image data, just how it is rendered by a printer into physical size. Rescaling an image is VERY different than altering it's DPI.

Last edited 2011


AdamRedwoods(Posted 2011) [#9]
Oh, you want to change the DPI value in the image data? You may have to use freeImage-- but if your image was created in 72DPI, then you're only going to have 72DPI worth of information for a 300DPI image... which means you'll have visual "blockiness" unless the printer (or the OS) auto-runs a smoothing algorithm on it for you.

If your image has enough information, then you'll be fine. Bicubic resizing can help add in information for tiny images, but it's not foolproof.

You'll need to test each approach to see what is best and what works best for you.


Yan(Posted 2011) [#10]
Gord love a duck...


I've run into this whilst pixmap mangling in the past. As it stands, SavePixmapPNG() leaves the DPI info undefined and I got tired of having to adjust manually.

Simple lash up, using code ripped from BRL's SavePixmapPNG()...

...Worked a treat.


gameproducer(Posted 2011) [#11]
Holy capoly Yan. That looks amazing. Testing rightaway...


gameproducer(Posted 2011) [#12]
...and it works like a charm. Thanks Ian!!