Ooook - thank you, Andre (and Michael as well) for pointing out what I
should have realized from the get-go: that for print formats pixels
mean precious little by themselves. Know thine media.
Andre Wobst wrote:
On 08.08.06, Manuel Gomes wrote:
Hello list, I've just started attempting to use pyx, and am faced with
an awkward situation when trying to feed it a JPG. A minimalistic example:
from pyx import *
print w,h #gives the correct values for width and height, im.info
has no DPI values in it.
i = bitmap.jpegimage(f)
c.insert(bitmap.bitmap(0,0,i,compressmode=None)) #error occurs here
When ran, the following error occurs:
File "/usr/lib/python2.4/site-packages/pyx/bitmap.py", line 179, in
widthdpi, heightdpi = image.info["dpi"] # XXX fails when no dpi
And sure enough - as noted in the snippet above, the image has no DPI
data. Much the same happens when trying to feed it the *im* image by
the method documented in the examples.
I DO, however, have both width and height for it... if only I could feed
them to pyx somehow. Am I missing a different constructor or some such ?
Or, in a slightly bassackwards manner, is there a way to inject DPI
information into the image with the PIL? Basically any workaround will do.
Well, what you get from the PIL is the width and the height in pixels
only. However, a jpeg image could also contain data of it's physical
resolution. The whole problem is, that PyX does not know how what size
your image should be (in physical coordinates, say in inches ... not
in dots). When the image contains a dpi information, PyX will use that
by default and will display this number of pixels *per* *inch*.
So all you need to do is to set a width (or a height, or both) in the
bitmap contstructor like in: