473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing large images

2 New Member
Hello all,

I've written and used other's python scripts (You've probably seen it) to print a bunch of photos in *.jpg format and seem to be having an Memory Error problem. After the first image is printed the script loads the next and I get the Memory Error. Each .jpg is between 40 and 75 mb. This script work with smaller (5 to 10mb) .jpg's.
Here's the script. If you have suggestions for better image handling, I'm all ears.
Thanks.
import win32print
import win32ui
import sys, os
import glob, time
import Image, ImageDraw, ImageFont
from PIL import Image, ImageWin

os.chdir ('R:/library/ninebynine/scanned/jpeg/ait/y2007')
img_list = glob.glob('*.jp g')
##def take90():
## time.sleep(90)
# 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.GetD efaultPrinter()
##os.char('D:/Ortho/jpg_outputs/sem/quarters/complete')
##img_list = glob.glob('*.jp g')
##file_name = "R:/library/ninebynine/scanned/jpeg/ita/y1995/ita01003.jpg"
##file_name = "D:/Ortho/jpg_outputs/sem/quarters/complete/fil12001_b.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.
for img in img_list:
print(img)
print "Sleeping for 5 minutes"
time.sleep(300)
print "Done sleeping attempting to print photo"
name = img
hDC = win32ui.CreateD C()
hDC.CreatePrint erDC (printer_name)
printable_area = hDC.GetDeviceCa ps (HORZRES), hDC.GetDeviceCa ps (VERTRES)
printer_size = hDC.GetDeviceCa ps (PHYSICALWIDTH) , hDC.GetDeviceCa ps (PHYSICALHEIGHT )
printer_margins = hDC.GetDeviceCa ps (PHYSICALOFFSET X), hDC.GetDeviceCa ps (PHYSICALOFFSET Y)

#
# 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[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.GetHandleO utput(), (x1, y1, x2, y2))

hDC.EndPage()
hDC.EndDoc()
hDC.DeleteDC()

Thanks again.
Dennis
May 28 '08 #1
0 1521

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2689
by: Frank.Sebesta | last post by:
I have a employees database with a picture that shows on a form with employee information. Similar to the Northwinds sample database. When I print the record, my output is only the data and does not include the picture. My pictures reside on my C drive. How can I get the picture to print with the record or I would be happy to just print the...
1
1210
by: Jos Roijakkers | last post by:
I am writing a program in Visual Studio 2005 (VB) that can print scanned images (saved as jpg-files). The printing is done by the following code: Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage Dim i As Integer Dim intPrintAreaHeight,...
6
3238
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would...
2
3026
by: letsgetsilly | last post by:
I'm developing the external corporate website for my company in Visual Studio 2003 using html, css, and a user web control for the header/navigation. When I try to print any of the pages only the header image (an <img> located in the Web User control) and the footer (also <img>) will print, but none of the text, graphics, background colors, or...
1
1967
by: ian.hubling | last post by:
I'm not sure if this is a javascript or a CSS issue... I'm looking for a way to force the printing of a background image when a page is printed. I'm dealing with a couple of large corporate policy manuals. Some of the material is archived. The archived pages have watermarks to visually identify them as outdated material. However, if the...
4
1946
by: Prakash | last post by:
I'm developing an HR package which would contain the Employees Photo + upto 3 pages (pictures) of his Passport + pictures of his Driving License and Residence Card. If the user wants to print the Passport Copies, Driving License, Residence Card, etc. what is the best method to accomplish this ? Best Rgds, Prakash.
8
5880
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic...
8
6380
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am looking for. My problem is that i have to upload images and store them. I am using filesystem for that. setup is something like this, their will...
0
1678
by: gnewsgroup | last post by:
In my asp.net 2.0 web application. I create chart images on the fly by getting the data from the database. These chart images all have fixed width, but the height is dynamic depending on the number of rows in the table returned from the database. These chart images are put into an HTML table through code-behind. They display nicely in...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
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 we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.