473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change dpi without changing pixels dimensions with PIL?

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
2 8356
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
9093
by: TheKeith | last post by:
I don't know much about javascript, so take it easy on me. Is there a way to dynamically change a CSS layers dimensions on the fly. Here is what I'm doing. I have a bunch of thumbnails that when...
3
24510
by: jeff | last post by:
Hello, I have a form that submits it's values to a pop-up window. I've simplied the code: <form name="formname" action="action.php" target="windowName" method="post" onsubmit="window.open('',...
14
11017
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
6
9448
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run...
8
8479
by: lauren quantrell | last post by:
Is there a way to force a change in a user's screen resolution using VBA code without having any input from the user? Example: User John Backwards has his screen set to 800 x 600 pixels. Backwards...
4
21471
by: Unknown | last post by:
Does anyone know how I would change the Hue of a bitmap I have? I tried looking for a class that would help me, but all I can find is methods that retrieve Hue values and not change them..
3
12718
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
2
1872
by: Marcel Brekelmans | last post by:
Hello, I save and restore the position and dimensions of a form using 'this.DeskTopBounds'. However, every time I open the form its Height grows with 19 or so pixels! Is there something I should...
0
1686
by: Stan Brown | last post by:
For some time now, I've been wanting to improve the look of the menus at my site http://www.tc3.edu/instruct/sbrown/stat/ . I like way these two work, opening a submenu when hovering on a...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.