4getcaptcha.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from PIL import Image
  2. def main():
  3. birds = Image.open("captcha3.jpeg") # birds
  4. fumoPlushies = Image.open("captcha2.jpeg") # fumo plushies
  5. minecraft = Image.open("captcha.jpeg") # minecraft
  6. #getText(birds)
  7. getImages(birds)
  8. def getText(image):
  9. textMargin = (0, 0, 400, 27)
  10. text = image.crop(textMargin)
  11. text.save("text.jpeg")
  12. text.show()
  13. def getImages(image):
  14. imageMargin = (0, 27, 400, 427)
  15. images = image.crop(imageMargin)
  16. images.save("images.jpeg")
  17. images.show()
  18. # All images are 100x100
  19. width = 100
  20. height = 100
  21. imageGrid = []
  22. for row in list(range(4)):
  23. imageRow = []
  24. for cell in list(range(4)):
  25. #imageRow += [f"{cell * width}, {row * height}, {(cell + 1) * width}, {(row + 1) * height}"]
  26. imageRow += [images.crop((cell * width, row * height, (cell + 1) * width, (row + 1) * height))]
  27. imageGrid += [imageRow]
  28. print(imageGrid)
  29. for i, image in enumerate(imageGrid):
  30. for j, img in enumerate(image):
  31. img.save(f"img{i}-{j}.jpeg")
  32. if __name__ == "__main__":
  33. main()