[Image-SIG] (no subject)

zcwaa22@ucl.ac.uk zcwaa22 at ucl.ac.uk
Sun Nov 27 22:54:02 CET 2005


Hi all,

Ive been working on a project which uses blender, python and pil but due to
restrictions in the current version of blender ive had to revert to an older
version[2.25] this means older python and older pil. Im now using python 2.0
and PIL 1.1.1.
ive been changing my scripts so that they work with these other versions but am
runnig into problems with PIL, basically in my project blender takes a
screenshot wihch PIL then prints on the default printer, this used to work fine
but with the older PIL all i get is a page full of black where the image should
be. If any of you who have any knowledge of old versions of PIL could help me
that would be great, below is the script:(which i stole from the internet
somewhere)

########################################################################
if own.printer == 1:
   import win32print
   import win32ui
   from PIL import Image, ImageWin

   import Rasterizer
   file_name = "test_a%04d.jpg" % own.printer_count
   #####filename = "anim%04d.tga" % obj.frame
   Rasterizer.makeScreenshot(file_name)

   #
   # Constants for GetDeviceCaps
   #
   #
   # HORZRES / VERTRES = printable area
   #
   HORZRES = 8
   VERTRES = 10
   #
   # LOGPIXELS = dots per inch
   #
   LOGPIXELSX = 88
   LOGPIXELSY = 90
   #
   # PHYSICALWIDTH/HEIGHT = total area
   #
   PHYSICALWIDTH = 110
   PHYSICALHEIGHT = 111
   #
   # PHYSICALOFFSETX/Y = left / top margin
   #
   PHYSICALOFFSETX = 112
   PHYSICALOFFSETY = 113

   printer_name = win32print.GetDefaultPrinter ()
   ####file_name = "test.jpg"

   #
   # You can only write a Device-independent bitmap
   #  directly to a Windows device context; therefore
   #  we need (for ease) to use the Python Imaging
   #  Library to manipulate the image.
   #
   # Create a device context from a named printer
   #  and assess the printable size of the paper.
   #
   hDC = win32ui.CreateDC ()
   hDC.CreatePrinterDC (printer_name)
   printable_area = hDC.GetDeviceCaps (HORZRES), hDC.GetDeviceCaps (VERTRES)
   printer_size = hDC.GetDeviceCaps (PHYSICALWIDTH), hDC.GetDeviceCaps
(PHYSICALHEIGHT)
   printer_margins = hDC.GetDeviceCaps (PHYSICALOFFSETX), hDC.GetDeviceCaps
(PHYSICALOFFSETY)

   #
   # Open the image, rotate it if it's wider than
   #  it is high, and work out how much to multiply
   #  each pixel by to get it as big as possible on
   #  the page without distorting.
   #
   bmp = Image.open (file_name)
   if bmp.size[0] > bmp.size[1]:
     bmp = bmp.rotate (90)
   ratios = [1.0 * printable_area[0] / bmp.size[0], 1.0 * printable_area[1] /
bmp.size[1]]
   scale = min (ratios)

   #
   # Start the print job, and draw the bitmap to
   #  the printer device at the scaled size.
   #
   hDC.StartDoc (file_name)
   hDC.StartPage ()

   dib = ImageWin.Dib (bmp)
   scaled_size = tuple ([scale * i for i in bmp.size])
   x = (printer_size[0] - scaled_size[0]) / 2
   y = (printer_size[1] - scaled_size[1]) / 2
   dib.draw (hDC.GetHandleOutput (), (x, y) + scaled_size)

   hDC.EndPage ()
   hDC.EndDoc ()

   own.printer_count +=1
   own.printer=0

##########################################################################
ive had to change

dib = ImageWin.Dib (bmp)

to

dib = ImageWin.Dib (bmp,(1,1))


Any help would be greatly appreciated

Thanks

Will Hurt



More information about the Image-SIG mailing list