By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

change dpi without changing pixels dimensions with PIL?

P: n/a
Hi there,

In Photoshop I can, when I want to change the dpi(dots per inch) of a
picture, arrange that the picture won't be resized. Do you know of a way, I
can accomplish this in python with PIL? If I use this script it changes the
dpi, but the picture becomes huge.

Thanks

Arjen

import sys
import Image
import os
a=sys.argv[1]
print a
c="or"+a
b=os.system("rename %s %s" % (a, c))
im=Image.open(c)
print im.info["dpi"]
im.save(a, dpi=(150, 150)
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
duikboot wrote:
Hi there,

In Photoshop I can, when I want to change the dpi(dots per inch) of a
picture, arrange that the picture won't be resized. Do you know of a way, I
can accomplish this in python with PIL? If I use this script it changes the
dpi, but the picture becomes huge.

Thanks


I might be completely wrong, but I think you have an error here.
Basically, a monitor has a set resolution (the resoultion at which you
run your graphics card). That resolution has a certain number of dots
per inch. So, if you increase the dots per inch of an image, you are
making it bigger and will require more monitor space or page area to
show or print it. What you are doing with Photoshop, most probably, is
increase the Dots Per Inch (DPI) AND rescaling it only for viewing
purposes on your screen. So although you see it the same size, the
picture surely is bigger. If that's the case, your script is doing what
it's supposed to do, but you need to "fit to screen" or something like
that if you want it to remain the same size ONLY for viewing purposes.

Gedece
Jul 18 '05 #2

P: n/a
"duikboot" <a@spam.nl> wrote:
In Photoshop I can, when I want to change the dpi(dots per inch) of a
picture, arrange that the picture won't be resized. Do you know of a way, I
can accomplish this in python with PIL? If I use this script it changes the
dpi, but the picture becomes huge.

Thanks

Arjen

import sys
import Image
import os
a=sys.argv[1]
print a
c="or"+a
b=os.system("rename %s %s" % (a, c))
That's usually spelled os.rename(a, c)
im=Image.open(c)
print im.info["dpi"]
im.save(a, dpi=(150, 150))


I think you're confusing image size with file size.

"Image.open" loads the image into a PIL Image object, and "save"
creates a new file from the contents of that object. The image size
(in pixels) doesn't change when you do this.

However, the file size may change. For some file formats, PIL can
read compressed files but not write files using the same compression
(usually for legal reasons). GIF is one such example. TIFF LZW is
another one.

If you can, use PNG instead.

</F>


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.