summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/captcha/LinksaveIn.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/module/captcha/LinksaveIn.py b/module/captcha/LinksaveIn.py
new file mode 100644
index 000000000..cd4e97f87
--- /dev/null
+++ b/module/captcha/LinksaveIn.py
@@ -0,0 +1,46 @@
+from captcha import OCR
+import Image
+
+class LinksaveIn(OCR):
+ def __init__(self):
+ OCR.__init__(self)
+
+ def load_image(self, image):
+ im = Image.open(image)
+ frame_nr = 0
+
+ lut = im.resize((256, 1))
+ lut.putdata(range(256))
+ lut = list(lut.convert("RGB").getdata())
+
+ new = Image.new("RGB", im.size)
+ npix = new.load()
+ while True:
+ try:
+ im.seek(frame_nr)
+ except EOFError:
+ break
+ frame = im.copy()
+ pix = frame.load()
+ for x in range(frame.size[0]):
+ for y in range(frame.size[1]):
+ if lut[pix[x, y]] != (0,0,0):
+ npix[x, y] = lut[pix[x, y]]
+ frame_nr += 1
+ self.image = new.copy()
+ self.pixels = self.image.load()
+ self.result_captcha = ''
+
+ def get_captcha(self, image):
+ self.load_image(image)
+ self.run_tesser()
+
+ return self.result_captcha
+
+if __name__ == '__main__':
+ import urllib
+ ocr = LinksaveIn()
+ testurl = "http://linksave.in/captcha/cap.php?hsh=2229185&code=ZzHdhl3UffV3lXTH5U4b7nShXj%2Bwma1vyoNBcbc6lcc%3D"
+ urllib.urlretrieve(testurl, "captcha.gif")
+
+ print ocr.get_captcha('captcha.gif')