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 glob, shutil, datetime, time
import sys, os
import Image, ImageDraw, ImageFont
from PIL import Image, ImageWin
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()
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)
if bmp.size > bmp.size:
bmp = bmp.rotate (90)
ratios = [1.0 * printable_area / bmp.size, 1.0 * printable_area / bmp.size]
scale = min (ratios)
# Start the print job, and draw the bitmap to
# the printer device at the scaled size.
dib = ImageWin.Dib (bmp)
scaled_width, scaled_height = [int (scale * i) for i in bmp.size]
x1 = int ((printer_size - scaled_width) / 2)
y1 = int ((printer_size - scaled_height) / 2)
x2 = x1 + scaled_width
y2 = y1 + scaled_height
dib.draw (hDC.GetHandleOutput(), (x1, y1, x2, y2))
This should be an easy script but, I just can't get it to work.