I'm trying to print a (or many) large aerial photos converted from tiff's to jpeg's and cannot seem to get it done without a MemoryError message.
These files are between 6 and 15 mb is size.
These images are 9x9 photos with these dimensions:
Width = 11705
Height = 11712
Block Width = 11705
I've been able to print 2 and 3 mb file size images with these dimensions:
Width, Height and block Width about = 7500
I'm not sure if it's the file size or the dimensions that's giving me trouble.
I'm using the code from Tim's Golden Python scripts with a few alterations.
import win32print
import win32ui
import glob, shutil, datetime, time
import sys, os
import Image, ImageDraw, ImageFont
from PIL import Image, ImageWin
import ImageOps
from path import path
# Constants for GetDeviceCaps
#
#
# HORZRES / VERTRES = printable area
#
HORZRES = 10
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()
d = path(print_jpeg_dir)
for f in d.walkfiles('*.jpg'):
scan = f.splitpath()[-1]
name = f
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 (name)
## bmp.show()
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 (name)
hDC.StartPage()
dib = ImageWin.Dib (bmp)
scaled_width, scaled_height = [int (scale * i) for i in bmp.size]
x1 = int ((printer_size[0] - scaled_width) / 2)
y1 = int ((printer_size[1] - scaled_height) / 2)
x2 = x1 + scaled_width
y2 = y1 + scaled_height
dib.draw (hDC.GetHandleOutput(), (x1, y1, x2, y2))
hDC.EndPage()
hDC.EndDoc()
hDC.DeleteDC()
This should be an easy script but, I just can't get it to work.
Any ideas?
Thanks.
-Dennis