@ai-ecoverse/py-pillow 12.3.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/LICENSE +30 -0
  2. package/README.md +4 -0
  3. package/lib/python3.14/site-packages/PIL/AvifImagePlugin.py +295 -0
  4. package/lib/python3.14/site-packages/PIL/BdfFontFile.py +124 -0
  5. package/lib/python3.14/site-packages/PIL/BlpImagePlugin.py +498 -0
  6. package/lib/python3.14/site-packages/PIL/BmpImagePlugin.py +514 -0
  7. package/lib/python3.14/site-packages/PIL/BufrStubImagePlugin.py +72 -0
  8. package/lib/python3.14/site-packages/PIL/ContainerIO.py +173 -0
  9. package/lib/python3.14/site-packages/PIL/CurImagePlugin.py +103 -0
  10. package/lib/python3.14/site-packages/PIL/DcxImagePlugin.py +84 -0
  11. package/lib/python3.14/site-packages/PIL/DdsImagePlugin.py +632 -0
  12. package/lib/python3.14/site-packages/PIL/EpsImagePlugin.py +484 -0
  13. package/lib/python3.14/site-packages/PIL/ExifTags.py +384 -0
  14. package/lib/python3.14/site-packages/PIL/FitsImagePlugin.py +153 -0
  15. package/lib/python3.14/site-packages/PIL/FliImagePlugin.py +184 -0
  16. package/lib/python3.14/site-packages/PIL/FontFile.py +160 -0
  17. package/lib/python3.14/site-packages/PIL/FpxImagePlugin.py +262 -0
  18. package/lib/python3.14/site-packages/PIL/FtexImagePlugin.py +115 -0
  19. package/lib/python3.14/site-packages/PIL/GbrImagePlugin.py +103 -0
  20. package/lib/python3.14/site-packages/PIL/GdImageFile.py +104 -0
  21. package/lib/python3.14/site-packages/PIL/GifImagePlugin.py +1223 -0
  22. package/lib/python3.14/site-packages/PIL/GimpGradientFile.py +154 -0
  23. package/lib/python3.14/site-packages/PIL/GimpPaletteFile.py +75 -0
  24. package/lib/python3.14/site-packages/PIL/GribStubImagePlugin.py +72 -0
  25. package/lib/python3.14/site-packages/PIL/Hdf5StubImagePlugin.py +72 -0
  26. package/lib/python3.14/site-packages/PIL/IcnsImagePlugin.py +401 -0
  27. package/lib/python3.14/site-packages/PIL/IcoImagePlugin.py +396 -0
  28. package/lib/python3.14/site-packages/PIL/ImImagePlugin.py +390 -0
  29. package/lib/python3.14/site-packages/PIL/Image.py +4385 -0
  30. package/lib/python3.14/site-packages/PIL/ImageChops.py +311 -0
  31. package/lib/python3.14/site-packages/PIL/ImageCms.py +1078 -0
  32. package/lib/python3.14/site-packages/PIL/ImageColor.py +320 -0
  33. package/lib/python3.14/site-packages/PIL/ImageDraw.py +1002 -0
  34. package/lib/python3.14/site-packages/PIL/ImageDraw2.py +244 -0
  35. package/lib/python3.14/site-packages/PIL/ImageEnhance.py +113 -0
  36. package/lib/python3.14/site-packages/PIL/ImageFile.py +938 -0
  37. package/lib/python3.14/site-packages/PIL/ImageFilter.py +617 -0
  38. package/lib/python3.14/site-packages/PIL/ImageFont.py +1330 -0
  39. package/lib/python3.14/site-packages/PIL/ImageGrab.py +234 -0
  40. package/lib/python3.14/site-packages/PIL/ImageMath.py +314 -0
  41. package/lib/python3.14/site-packages/PIL/ImageMode.py +85 -0
  42. package/lib/python3.14/site-packages/PIL/ImageMorph.py +317 -0
  43. package/lib/python3.14/site-packages/PIL/ImageOps.py +749 -0
  44. package/lib/python3.14/site-packages/PIL/ImagePalette.py +290 -0
  45. package/lib/python3.14/site-packages/PIL/ImagePath.py +20 -0
  46. package/lib/python3.14/site-packages/PIL/ImageQt.py +219 -0
  47. package/lib/python3.14/site-packages/PIL/ImageSequence.py +88 -0
  48. package/lib/python3.14/site-packages/PIL/ImageShow.py +367 -0
  49. package/lib/python3.14/site-packages/PIL/ImageStat.py +167 -0
  50. package/lib/python3.14/site-packages/PIL/ImageText.py +509 -0
  51. package/lib/python3.14/site-packages/PIL/ImageTk.py +266 -0
  52. package/lib/python3.14/site-packages/PIL/ImageTransform.py +136 -0
  53. package/lib/python3.14/site-packages/PIL/ImageWin.py +247 -0
  54. package/lib/python3.14/site-packages/PIL/ImtImagePlugin.py +103 -0
  55. package/lib/python3.14/site-packages/PIL/IptcImagePlugin.py +226 -0
  56. package/lib/python3.14/site-packages/PIL/Jpeg2KImagePlugin.py +466 -0
  57. package/lib/python3.14/site-packages/PIL/JpegImagePlugin.py +889 -0
  58. package/lib/python3.14/site-packages/PIL/JpegPresets.py +242 -0
  59. package/lib/python3.14/site-packages/PIL/McIdasImagePlugin.py +78 -0
  60. package/lib/python3.14/site-packages/PIL/MicImagePlugin.py +103 -0
  61. package/lib/python3.14/site-packages/PIL/MpegImagePlugin.py +84 -0
  62. package/lib/python3.14/site-packages/PIL/MpoImagePlugin.py +203 -0
  63. package/lib/python3.14/site-packages/PIL/MspImagePlugin.py +200 -0
  64. package/lib/python3.14/site-packages/PIL/PSDraw.py +238 -0
  65. package/lib/python3.14/site-packages/PIL/PaletteFile.py +54 -0
  66. package/lib/python3.14/site-packages/PIL/PalmImagePlugin.py +217 -0
  67. package/lib/python3.14/site-packages/PIL/PcdImagePlugin.py +68 -0
  68. package/lib/python3.14/site-packages/PIL/PcfFontFile.py +256 -0
  69. package/lib/python3.14/site-packages/PIL/PcxImagePlugin.py +232 -0
  70. package/lib/python3.14/site-packages/PIL/PdfImagePlugin.py +315 -0
  71. package/lib/python3.14/site-packages/PIL/PdfParser.py +1092 -0
  72. package/lib/python3.14/site-packages/PIL/PixarImagePlugin.py +72 -0
  73. package/lib/python3.14/site-packages/PIL/PngImagePlugin.py +1578 -0
  74. package/lib/python3.14/site-packages/PIL/PpmImagePlugin.py +375 -0
  75. package/lib/python3.14/site-packages/PIL/PsdImagePlugin.py +339 -0
  76. package/lib/python3.14/site-packages/PIL/QoiImagePlugin.py +235 -0
  77. package/lib/python3.14/site-packages/PIL/SgiImagePlugin.py +231 -0
  78. package/lib/python3.14/site-packages/PIL/SpiderImagePlugin.py +332 -0
  79. package/lib/python3.14/site-packages/PIL/SunImagePlugin.py +145 -0
  80. package/lib/python3.14/site-packages/PIL/TarIO.py +61 -0
  81. package/lib/python3.14/site-packages/PIL/TgaImagePlugin.py +284 -0
  82. package/lib/python3.14/site-packages/PIL/TiffImagePlugin.py +2354 -0
  83. package/lib/python3.14/site-packages/PIL/TiffTags.py +566 -0
  84. package/lib/python3.14/site-packages/PIL/WalImageFile.py +129 -0
  85. package/lib/python3.14/site-packages/PIL/WebPImagePlugin.py +322 -0
  86. package/lib/python3.14/site-packages/PIL/WmfImagePlugin.py +183 -0
  87. package/lib/python3.14/site-packages/PIL/XVThumbImagePlugin.py +83 -0
  88. package/lib/python3.14/site-packages/PIL/XbmImagePlugin.py +98 -0
  89. package/lib/python3.14/site-packages/PIL/XpmImagePlugin.py +157 -0
  90. package/lib/python3.14/site-packages/PIL/__init__.py +87 -0
  91. package/lib/python3.14/site-packages/PIL/__main__.py +7 -0
  92. package/lib/python3.14/site-packages/PIL/__pycache__/AvifImagePlugin.cpython-314.pyc +0 -0
  93. package/lib/python3.14/site-packages/PIL/__pycache__/BdfFontFile.cpython-314.pyc +0 -0
  94. package/lib/python3.14/site-packages/PIL/__pycache__/BlpImagePlugin.cpython-314.pyc +0 -0
  95. package/lib/python3.14/site-packages/PIL/__pycache__/BmpImagePlugin.cpython-314.pyc +0 -0
  96. package/lib/python3.14/site-packages/PIL/__pycache__/BufrStubImagePlugin.cpython-314.pyc +0 -0
  97. package/lib/python3.14/site-packages/PIL/__pycache__/ContainerIO.cpython-314.pyc +0 -0
  98. package/lib/python3.14/site-packages/PIL/__pycache__/CurImagePlugin.cpython-314.pyc +0 -0
  99. package/lib/python3.14/site-packages/PIL/__pycache__/DcxImagePlugin.cpython-314.pyc +0 -0
  100. package/lib/python3.14/site-packages/PIL/__pycache__/DdsImagePlugin.cpython-314.pyc +0 -0
  101. package/lib/python3.14/site-packages/PIL/__pycache__/EpsImagePlugin.cpython-314.pyc +0 -0
  102. package/lib/python3.14/site-packages/PIL/__pycache__/ExifTags.cpython-314.pyc +0 -0
  103. package/lib/python3.14/site-packages/PIL/__pycache__/FitsImagePlugin.cpython-314.pyc +0 -0
  104. package/lib/python3.14/site-packages/PIL/__pycache__/FliImagePlugin.cpython-314.pyc +0 -0
  105. package/lib/python3.14/site-packages/PIL/__pycache__/FontFile.cpython-314.pyc +0 -0
  106. package/lib/python3.14/site-packages/PIL/__pycache__/FpxImagePlugin.cpython-314.pyc +0 -0
  107. package/lib/python3.14/site-packages/PIL/__pycache__/FtexImagePlugin.cpython-314.pyc +0 -0
  108. package/lib/python3.14/site-packages/PIL/__pycache__/GbrImagePlugin.cpython-314.pyc +0 -0
  109. package/lib/python3.14/site-packages/PIL/__pycache__/GdImageFile.cpython-314.pyc +0 -0
  110. package/lib/python3.14/site-packages/PIL/__pycache__/GifImagePlugin.cpython-314.pyc +0 -0
  111. package/lib/python3.14/site-packages/PIL/__pycache__/GimpGradientFile.cpython-314.pyc +0 -0
  112. package/lib/python3.14/site-packages/PIL/__pycache__/GimpPaletteFile.cpython-314.pyc +0 -0
  113. package/lib/python3.14/site-packages/PIL/__pycache__/GribStubImagePlugin.cpython-314.pyc +0 -0
  114. package/lib/python3.14/site-packages/PIL/__pycache__/Hdf5StubImagePlugin.cpython-314.pyc +0 -0
  115. package/lib/python3.14/site-packages/PIL/__pycache__/IcnsImagePlugin.cpython-314.pyc +0 -0
  116. package/lib/python3.14/site-packages/PIL/__pycache__/IcoImagePlugin.cpython-314.pyc +0 -0
  117. package/lib/python3.14/site-packages/PIL/__pycache__/ImImagePlugin.cpython-314.pyc +0 -0
  118. package/lib/python3.14/site-packages/PIL/__pycache__/Image.cpython-314.pyc +0 -0
  119. package/lib/python3.14/site-packages/PIL/__pycache__/ImageChops.cpython-314.pyc +0 -0
  120. package/lib/python3.14/site-packages/PIL/__pycache__/ImageCms.cpython-314.pyc +0 -0
  121. package/lib/python3.14/site-packages/PIL/__pycache__/ImageColor.cpython-314.pyc +0 -0
  122. package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw.cpython-314.pyc +0 -0
  123. package/lib/python3.14/site-packages/PIL/__pycache__/ImageDraw2.cpython-314.pyc +0 -0
  124. package/lib/python3.14/site-packages/PIL/__pycache__/ImageEnhance.cpython-314.pyc +0 -0
  125. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFile.cpython-314.pyc +0 -0
  126. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFilter.cpython-314.pyc +0 -0
  127. package/lib/python3.14/site-packages/PIL/__pycache__/ImageFont.cpython-314.pyc +0 -0
  128. package/lib/python3.14/site-packages/PIL/__pycache__/ImageGrab.cpython-314.pyc +0 -0
  129. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMath.cpython-314.pyc +0 -0
  130. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMode.cpython-314.pyc +0 -0
  131. package/lib/python3.14/site-packages/PIL/__pycache__/ImageMorph.cpython-314.pyc +0 -0
  132. package/lib/python3.14/site-packages/PIL/__pycache__/ImageOps.cpython-314.pyc +0 -0
  133. package/lib/python3.14/site-packages/PIL/__pycache__/ImagePalette.cpython-314.pyc +0 -0
  134. package/lib/python3.14/site-packages/PIL/__pycache__/ImagePath.cpython-314.pyc +0 -0
  135. package/lib/python3.14/site-packages/PIL/__pycache__/ImageQt.cpython-314.pyc +0 -0
  136. package/lib/python3.14/site-packages/PIL/__pycache__/ImageSequence.cpython-314.pyc +0 -0
  137. package/lib/python3.14/site-packages/PIL/__pycache__/ImageShow.cpython-314.pyc +0 -0
  138. package/lib/python3.14/site-packages/PIL/__pycache__/ImageStat.cpython-314.pyc +0 -0
  139. package/lib/python3.14/site-packages/PIL/__pycache__/ImageText.cpython-314.pyc +0 -0
  140. package/lib/python3.14/site-packages/PIL/__pycache__/ImageTk.cpython-314.pyc +0 -0
  141. package/lib/python3.14/site-packages/PIL/__pycache__/ImageTransform.cpython-314.pyc +0 -0
  142. package/lib/python3.14/site-packages/PIL/__pycache__/ImageWin.cpython-314.pyc +0 -0
  143. package/lib/python3.14/site-packages/PIL/__pycache__/ImtImagePlugin.cpython-314.pyc +0 -0
  144. package/lib/python3.14/site-packages/PIL/__pycache__/IptcImagePlugin.cpython-314.pyc +0 -0
  145. package/lib/python3.14/site-packages/PIL/__pycache__/Jpeg2KImagePlugin.cpython-314.pyc +0 -0
  146. package/lib/python3.14/site-packages/PIL/__pycache__/JpegImagePlugin.cpython-314.pyc +0 -0
  147. package/lib/python3.14/site-packages/PIL/__pycache__/JpegPresets.cpython-314.pyc +0 -0
  148. package/lib/python3.14/site-packages/PIL/__pycache__/McIdasImagePlugin.cpython-314.pyc +0 -0
  149. package/lib/python3.14/site-packages/PIL/__pycache__/MicImagePlugin.cpython-314.pyc +0 -0
  150. package/lib/python3.14/site-packages/PIL/__pycache__/MpegImagePlugin.cpython-314.pyc +0 -0
  151. package/lib/python3.14/site-packages/PIL/__pycache__/MpoImagePlugin.cpython-314.pyc +0 -0
  152. package/lib/python3.14/site-packages/PIL/__pycache__/MspImagePlugin.cpython-314.pyc +0 -0
  153. package/lib/python3.14/site-packages/PIL/__pycache__/PSDraw.cpython-314.pyc +0 -0
  154. package/lib/python3.14/site-packages/PIL/__pycache__/PaletteFile.cpython-314.pyc +0 -0
  155. package/lib/python3.14/site-packages/PIL/__pycache__/PalmImagePlugin.cpython-314.pyc +0 -0
  156. package/lib/python3.14/site-packages/PIL/__pycache__/PcdImagePlugin.cpython-314.pyc +0 -0
  157. package/lib/python3.14/site-packages/PIL/__pycache__/PcfFontFile.cpython-314.pyc +0 -0
  158. package/lib/python3.14/site-packages/PIL/__pycache__/PcxImagePlugin.cpython-314.pyc +0 -0
  159. package/lib/python3.14/site-packages/PIL/__pycache__/PdfImagePlugin.cpython-314.pyc +0 -0
  160. package/lib/python3.14/site-packages/PIL/__pycache__/PdfParser.cpython-314.pyc +0 -0
  161. package/lib/python3.14/site-packages/PIL/__pycache__/PixarImagePlugin.cpython-314.pyc +0 -0
  162. package/lib/python3.14/site-packages/PIL/__pycache__/PngImagePlugin.cpython-314.pyc +0 -0
  163. package/lib/python3.14/site-packages/PIL/__pycache__/PpmImagePlugin.cpython-314.pyc +0 -0
  164. package/lib/python3.14/site-packages/PIL/__pycache__/PsdImagePlugin.cpython-314.pyc +0 -0
  165. package/lib/python3.14/site-packages/PIL/__pycache__/QoiImagePlugin.cpython-314.pyc +0 -0
  166. package/lib/python3.14/site-packages/PIL/__pycache__/SgiImagePlugin.cpython-314.pyc +0 -0
  167. package/lib/python3.14/site-packages/PIL/__pycache__/SpiderImagePlugin.cpython-314.pyc +0 -0
  168. package/lib/python3.14/site-packages/PIL/__pycache__/SunImagePlugin.cpython-314.pyc +0 -0
  169. package/lib/python3.14/site-packages/PIL/__pycache__/TarIO.cpython-314.pyc +0 -0
  170. package/lib/python3.14/site-packages/PIL/__pycache__/TgaImagePlugin.cpython-314.pyc +0 -0
  171. package/lib/python3.14/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-314.pyc +0 -0
  172. package/lib/python3.14/site-packages/PIL/__pycache__/TiffTags.cpython-314.pyc +0 -0
  173. package/lib/python3.14/site-packages/PIL/__pycache__/WalImageFile.cpython-314.pyc +0 -0
  174. package/lib/python3.14/site-packages/PIL/__pycache__/WebPImagePlugin.cpython-314.pyc +0 -0
  175. package/lib/python3.14/site-packages/PIL/__pycache__/WmfImagePlugin.cpython-314.pyc +0 -0
  176. package/lib/python3.14/site-packages/PIL/__pycache__/XVThumbImagePlugin.cpython-314.pyc +0 -0
  177. package/lib/python3.14/site-packages/PIL/__pycache__/XbmImagePlugin.cpython-314.pyc +0 -0
  178. package/lib/python3.14/site-packages/PIL/__pycache__/XpmImagePlugin.cpython-314.pyc +0 -0
  179. package/lib/python3.14/site-packages/PIL/__pycache__/__init__.cpython-314.pyc +0 -0
  180. package/lib/python3.14/site-packages/PIL/__pycache__/__main__.cpython-314.pyc +0 -0
  181. package/lib/python3.14/site-packages/PIL/__pycache__/_binary.cpython-314.pyc +0 -0
  182. package/lib/python3.14/site-packages/PIL/__pycache__/_deprecate.cpython-314.pyc +0 -0
  183. package/lib/python3.14/site-packages/PIL/__pycache__/_tkinter_finder.cpython-314.pyc +0 -0
  184. package/lib/python3.14/site-packages/PIL/__pycache__/_typing.cpython-314.pyc +0 -0
  185. package/lib/python3.14/site-packages/PIL/__pycache__/_util.cpython-314.pyc +0 -0
  186. package/lib/python3.14/site-packages/PIL/__pycache__/_version.cpython-314.pyc +0 -0
  187. package/lib/python3.14/site-packages/PIL/__pycache__/features.cpython-314.pyc +0 -0
  188. package/lib/python3.14/site-packages/PIL/__pycache__/report.cpython-314.pyc +0 -0
  189. package/lib/python3.14/site-packages/PIL/_avif.pyi +3 -0
  190. package/lib/python3.14/site-packages/PIL/_binary.py +113 -0
  191. package/lib/python3.14/site-packages/PIL/_deprecate.py +72 -0
  192. package/lib/python3.14/site-packages/PIL/_imaging.cpython-314-wasm32-wasix.so +0 -0
  193. package/lib/python3.14/site-packages/PIL/_imaging.pyi +31 -0
  194. package/lib/python3.14/site-packages/PIL/_imagingcms.pyi +143 -0
  195. package/lib/python3.14/site-packages/PIL/_imagingft.cpython-314-wasm32-wasix.so +0 -0
  196. package/lib/python3.14/site-packages/PIL/_imagingft.pyi +70 -0
  197. package/lib/python3.14/site-packages/PIL/_imagingmath.cpython-314-wasm32-wasix.so +0 -0
  198. package/lib/python3.14/site-packages/PIL/_imagingmath.pyi +3 -0
  199. package/lib/python3.14/site-packages/PIL/_imagingmorph.cpython-314-wasm32-wasix.so +0 -0
  200. package/lib/python3.14/site-packages/PIL/_imagingmorph.pyi +3 -0
  201. package/lib/python3.14/site-packages/PIL/_imagingtk.cpython-314-wasm32-wasix.so +0 -0
  202. package/lib/python3.14/site-packages/PIL/_imagingtk.pyi +3 -0
  203. package/lib/python3.14/site-packages/PIL/_tkinter_finder.py +20 -0
  204. package/lib/python3.14/site-packages/PIL/_typing.py +45 -0
  205. package/lib/python3.14/site-packages/PIL/_util.py +29 -0
  206. package/lib/python3.14/site-packages/PIL/_version.py +4 -0
  207. package/lib/python3.14/site-packages/PIL/_webp.pyi +3 -0
  208. package/lib/python3.14/site-packages/PIL/features.py +343 -0
  209. package/lib/python3.14/site-packages/PIL/py.typed +0 -0
  210. package/lib/python3.14/site-packages/PIL/report.py +5 -0
  211. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/METADATA +180 -0
  212. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/RECORD +117 -0
  213. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/WHEEL +5 -0
  214. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/licenses/LICENSE +30 -0
  215. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/top_level.txt +1 -0
  216. package/lib/python3.14/site-packages/pillow-12.3.0.dist-info/zip-safe +1 -0
  217. package/package.json +46 -0
@@ -0,0 +1,234 @@
1
+ #
2
+ # The Python Imaging Library
3
+ # $Id$
4
+ #
5
+ # screen grabber
6
+ #
7
+ # History:
8
+ # 2001-04-26 fl created
9
+ # 2001-09-17 fl use builtin driver, if present
10
+ # 2002-11-19 fl added grabclipboard support
11
+ #
12
+ # Copyright (c) 2001-2002 by Secret Labs AB
13
+ # Copyright (c) 2001-2002 by Fredrik Lundh
14
+ #
15
+ # See the README file for information on usage and redistribution.
16
+ #
17
+ from __future__ import annotations
18
+
19
+ import io
20
+ import os
21
+ import shutil
22
+ import subprocess
23
+ import sys
24
+ import tempfile
25
+
26
+ from . import Image
27
+
28
+ TYPE_CHECKING = False
29
+ if TYPE_CHECKING:
30
+ from . import ImageWin
31
+
32
+
33
+ def grab(
34
+ bbox: tuple[int, int, int, int] | None = None,
35
+ include_layered_windows: bool = False,
36
+ all_screens: bool = False,
37
+ xdisplay: str | None = None,
38
+ window: int | ImageWin.HWND | None = None,
39
+ *,
40
+ scale_down: bool = False,
41
+ ) -> Image.Image:
42
+ im: Image.Image
43
+ if xdisplay is None:
44
+ if sys.platform == "darwin":
45
+ fh, filepath = tempfile.mkstemp(".png")
46
+ os.close(fh)
47
+ args = ["screencapture"]
48
+ if window is not None:
49
+ args += ["-l", str(window)]
50
+ elif bbox:
51
+ left, top, right, bottom = bbox
52
+ args += ["-R", f"{left},{top},{right-left},{bottom-top}"]
53
+ args += ["-x", filepath]
54
+ retcode = subprocess.call(args)
55
+ if retcode:
56
+ raise subprocess.CalledProcessError(retcode, args)
57
+ im = Image.open(filepath)
58
+ im.load()
59
+ os.unlink(filepath)
60
+ if bbox:
61
+ if window is not None:
62
+ # Determine if the window was in Retina mode or not
63
+ # by capturing it without the shadow,
64
+ # and checking how different the width is
65
+ fh, filepath = tempfile.mkstemp(".png")
66
+ os.close(fh)
67
+ args = ["screencapture", "-l", str(window), "-o", "-x", filepath]
68
+ retcode = subprocess.call(args)
69
+ if retcode:
70
+ raise subprocess.CalledProcessError(retcode, args)
71
+ with Image.open(filepath) as im_no_shadow:
72
+ retina = im.width - im_no_shadow.width > 100
73
+ os.unlink(filepath)
74
+
75
+ # Since screencapture's -R does not work with -l,
76
+ # crop the image manually
77
+ if retina:
78
+ left, top, right, bottom = bbox
79
+ scale = 1 if scale_down else 2
80
+ im_cropped = im.resize(
81
+ ((right - left) * scale, (bottom - top) * scale),
82
+ box=tuple(coord * 2 for coord in bbox),
83
+ )
84
+ else:
85
+ im_cropped = im.crop(bbox)
86
+ im.close()
87
+ return im_cropped
88
+ elif scale_down:
89
+ im_resized = im.resize((right - left, bottom - top))
90
+ im.close()
91
+ return im_resized
92
+ return im
93
+ elif sys.platform == "win32":
94
+ if window is not None:
95
+ all_screens = -1
96
+ offset, size, data = Image.core.grabscreen_win32(
97
+ include_layered_windows,
98
+ all_screens,
99
+ int(window) if window is not None else 0,
100
+ )
101
+ im = Image.frombytes(
102
+ "RGB",
103
+ size,
104
+ data,
105
+ # RGB, 32-bit line padding, origin lower left corner
106
+ "raw",
107
+ "BGR",
108
+ (size[0] * 3 + 3) & -4,
109
+ -1,
110
+ )
111
+ if bbox:
112
+ x0, y0 = offset
113
+ left, top, right, bottom = bbox
114
+ im = im.crop((left - x0, top - y0, right - x0, bottom - y0))
115
+ return im
116
+ # Cast to Optional[str] needed for Windows and macOS.
117
+ display_name: str | None = xdisplay
118
+ try:
119
+ if not Image.core.HAVE_XCB:
120
+ msg = "Pillow was built without XCB support"
121
+ raise OSError(msg)
122
+ size, data = Image.core.grabscreen_x11(display_name)
123
+ except OSError:
124
+ if display_name is None and sys.platform not in ("darwin", "win32"):
125
+ if shutil.which("gnome-screenshot"):
126
+ args = ["gnome-screenshot", "-f"]
127
+ elif shutil.which("grim"):
128
+ args = ["grim"]
129
+ elif shutil.which("spectacle"):
130
+ args = ["spectacle", "-n", "-b", "-f", "-o"]
131
+ else:
132
+ raise
133
+ fh, filepath = tempfile.mkstemp(".png")
134
+ os.close(fh)
135
+ args.append(filepath)
136
+ retcode = subprocess.call(args)
137
+ if retcode:
138
+ raise subprocess.CalledProcessError(retcode, args)
139
+ im = Image.open(filepath)
140
+ im.load()
141
+ os.unlink(filepath)
142
+ if bbox:
143
+ im_cropped = im.crop(bbox)
144
+ im.close()
145
+ return im_cropped
146
+ return im
147
+ else:
148
+ raise
149
+ else:
150
+ im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
151
+ if bbox:
152
+ im = im.crop(bbox)
153
+ return im
154
+
155
+
156
+ def grabclipboard() -> Image.Image | list[str] | None:
157
+ if sys.platform == "darwin":
158
+ p = subprocess.run(
159
+ ["osascript", "-e", "get the clipboard as «class PNGf»"],
160
+ capture_output=True,
161
+ )
162
+ if p.returncode != 0:
163
+ return None
164
+
165
+ import binascii
166
+
167
+ data = io.BytesIO(binascii.unhexlify(p.stdout[11:-3]))
168
+ return Image.open(data)
169
+ elif sys.platform == "win32":
170
+ fmt, data = Image.core.grabclipboard_win32()
171
+ if fmt == "file": # CF_HDROP
172
+ import struct
173
+
174
+ o = struct.unpack_from("I", data)[0]
175
+ if data[16] == 0:
176
+ files = data[o:].decode("mbcs").split("\0")
177
+ else:
178
+ files = data[o:].decode("utf-16le").split("\0")
179
+ return files[: files.index("")]
180
+ if isinstance(data, bytes):
181
+ data = io.BytesIO(data)
182
+ if fmt == "png":
183
+ from . import PngImagePlugin
184
+
185
+ return PngImagePlugin.PngImageFile(data)
186
+ elif fmt == "DIB":
187
+ from . import BmpImagePlugin
188
+
189
+ return BmpImagePlugin.DibImageFile(data)
190
+ return None
191
+ else:
192
+ if os.getenv("WAYLAND_DISPLAY"):
193
+ session_type = "wayland"
194
+ elif os.getenv("DISPLAY"):
195
+ session_type = "x11"
196
+ else: # Session type check failed
197
+ session_type = None
198
+
199
+ if shutil.which("wl-paste") and session_type in ("wayland", None):
200
+ args = ["wl-paste", "-t", "image"]
201
+ elif shutil.which("xclip") and session_type in ("x11", None):
202
+ args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
203
+ else:
204
+ msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
205
+ raise NotImplementedError(msg)
206
+
207
+ p = subprocess.run(args, capture_output=True)
208
+ if p.returncode != 0:
209
+ err = p.stderr
210
+ for silent_error in [
211
+ # wl-paste, when the clipboard is empty
212
+ b"Nothing is copied",
213
+ # Ubuntu/Debian wl-paste, when the clipboard is empty
214
+ b"No selection",
215
+ # Ubuntu/Debian wl-paste, when an image isn't available
216
+ b"No suitable type of content copied",
217
+ # wl-paste or Ubuntu/Debian xclip, when an image isn't available
218
+ b" not available",
219
+ # xclip, when an image isn't available
220
+ b"cannot convert ",
221
+ # xclip, when the clipboard isn't initialized
222
+ b"xclip: Error: There is no owner for the ",
223
+ ]:
224
+ if silent_error in err:
225
+ return None
226
+ msg = f"{args[0]} error"
227
+ if err:
228
+ msg += f": {err.strip().decode()}"
229
+ raise ChildProcessError(msg)
230
+
231
+ data = io.BytesIO(p.stdout)
232
+ im = Image.open(data)
233
+ im.load()
234
+ return im
@@ -0,0 +1,314 @@
1
+ #
2
+ # The Python Imaging Library
3
+ # $Id$
4
+ #
5
+ # a simple math add-on for the Python Imaging Library
6
+ #
7
+ # History:
8
+ # 1999-02-15 fl Original PIL Plus release
9
+ # 2005-05-05 fl Simplified and cleaned up for PIL 1.1.6
10
+ # 2005-09-12 fl Fixed int() and float() for Python 2.4.1
11
+ #
12
+ # Copyright (c) 1999-2005 by Secret Labs AB
13
+ # Copyright (c) 2005 by Fredrik Lundh
14
+ #
15
+ # See the README file for information on usage and redistribution.
16
+ #
17
+ from __future__ import annotations
18
+
19
+ import builtins
20
+
21
+ from . import Image, _imagingmath
22
+
23
+ TYPE_CHECKING = False
24
+ if TYPE_CHECKING:
25
+ from collections.abc import Callable
26
+ from types import CodeType
27
+ from typing import Any
28
+
29
+
30
+ class _Operand:
31
+ """Wraps an image operand, providing standard operators"""
32
+
33
+ def __init__(self, im: Image.Image):
34
+ self.im = im
35
+
36
+ def __fixup(self, im1: _Operand | float) -> Image.Image:
37
+ # convert image to suitable mode
38
+ if isinstance(im1, _Operand):
39
+ # argument was an image.
40
+ if im1.im.mode in ("1", "L"):
41
+ return im1.im.convert("I")
42
+ elif im1.im.mode in ("I", "F"):
43
+ return im1.im
44
+ else:
45
+ msg = f"unsupported mode: {im1.im.mode}"
46
+ raise ValueError(msg)
47
+ else:
48
+ # argument was a constant
49
+ if isinstance(im1, (int, float)) and self.im.mode in ("1", "L", "I"):
50
+ return Image.new("I", self.im.size, im1)
51
+ else:
52
+ return Image.new("F", self.im.size, im1)
53
+
54
+ def apply(
55
+ self,
56
+ op: str,
57
+ im1: _Operand | float,
58
+ im2: _Operand | float | None = None,
59
+ mode: str | None = None,
60
+ ) -> _Operand:
61
+ im_1 = self.__fixup(im1)
62
+ if im2 is None:
63
+ # unary operation
64
+ out = Image.new(mode or im_1.mode, im_1.size, None)
65
+ try:
66
+ op = getattr(_imagingmath, f"{op}_{im_1.mode}")
67
+ except AttributeError as e:
68
+ msg = f"bad operand type for '{op}'"
69
+ raise TypeError(msg) from e
70
+ _imagingmath.unop(op, out.getim(), im_1.getim())
71
+ else:
72
+ # binary operation
73
+ im_2 = self.__fixup(im2)
74
+ if im_1.mode != im_2.mode:
75
+ # convert both arguments to floating point
76
+ if im_1.mode != "F":
77
+ im_1 = im_1.convert("F")
78
+ if im_2.mode != "F":
79
+ im_2 = im_2.convert("F")
80
+ if im_1.size != im_2.size:
81
+ # crop both arguments to a common size
82
+ size = (
83
+ min(im_1.size[0], im_2.size[0]),
84
+ min(im_1.size[1], im_2.size[1]),
85
+ )
86
+ if im_1.size != size:
87
+ im_1 = im_1.crop((0, 0) + size)
88
+ if im_2.size != size:
89
+ im_2 = im_2.crop((0, 0) + size)
90
+ out = Image.new(mode or im_1.mode, im_1.size, None)
91
+ try:
92
+ op = getattr(_imagingmath, f"{op}_{im_1.mode}")
93
+ except AttributeError as e:
94
+ msg = f"bad operand type for '{op}'"
95
+ raise TypeError(msg) from e
96
+ _imagingmath.binop(op, out.getim(), im_1.getim(), im_2.getim())
97
+ return _Operand(out)
98
+
99
+ # unary operators
100
+ def __bool__(self) -> bool:
101
+ # an image is "true" if it contains at least one non-zero pixel
102
+ return self.im.getbbox() is not None
103
+
104
+ def __abs__(self) -> _Operand:
105
+ return self.apply("abs", self)
106
+
107
+ def __pos__(self) -> _Operand:
108
+ return self
109
+
110
+ def __neg__(self) -> _Operand:
111
+ return self.apply("neg", self)
112
+
113
+ # binary operators
114
+ def __add__(self, other: _Operand | float) -> _Operand:
115
+ return self.apply("add", self, other)
116
+
117
+ def __radd__(self, other: _Operand | float) -> _Operand:
118
+ return self.apply("add", other, self)
119
+
120
+ def __sub__(self, other: _Operand | float) -> _Operand:
121
+ return self.apply("sub", self, other)
122
+
123
+ def __rsub__(self, other: _Operand | float) -> _Operand:
124
+ return self.apply("sub", other, self)
125
+
126
+ def __mul__(self, other: _Operand | float) -> _Operand:
127
+ return self.apply("mul", self, other)
128
+
129
+ def __rmul__(self, other: _Operand | float) -> _Operand:
130
+ return self.apply("mul", other, self)
131
+
132
+ def __truediv__(self, other: _Operand | float) -> _Operand:
133
+ return self.apply("div", self, other)
134
+
135
+ def __rtruediv__(self, other: _Operand | float) -> _Operand:
136
+ return self.apply("div", other, self)
137
+
138
+ def __mod__(self, other: _Operand | float) -> _Operand:
139
+ return self.apply("mod", self, other)
140
+
141
+ def __rmod__(self, other: _Operand | float) -> _Operand:
142
+ return self.apply("mod", other, self)
143
+
144
+ def __pow__(self, other: _Operand | float) -> _Operand:
145
+ return self.apply("pow", self, other)
146
+
147
+ def __rpow__(self, other: _Operand | float) -> _Operand:
148
+ return self.apply("pow", other, self)
149
+
150
+ # bitwise
151
+ def __invert__(self) -> _Operand:
152
+ return self.apply("invert", self)
153
+
154
+ def __and__(self, other: _Operand | float) -> _Operand:
155
+ return self.apply("and", self, other)
156
+
157
+ def __rand__(self, other: _Operand | float) -> _Operand:
158
+ return self.apply("and", other, self)
159
+
160
+ def __or__(self, other: _Operand | float) -> _Operand:
161
+ return self.apply("or", self, other)
162
+
163
+ def __ror__(self, other: _Operand | float) -> _Operand:
164
+ return self.apply("or", other, self)
165
+
166
+ def __xor__(self, other: _Operand | float) -> _Operand:
167
+ return self.apply("xor", self, other)
168
+
169
+ def __rxor__(self, other: _Operand | float) -> _Operand:
170
+ return self.apply("xor", other, self)
171
+
172
+ def __lshift__(self, other: _Operand | float) -> _Operand:
173
+ return self.apply("lshift", self, other)
174
+
175
+ def __rshift__(self, other: _Operand | float) -> _Operand:
176
+ return self.apply("rshift", self, other)
177
+
178
+ # logical
179
+ def __eq__(self, other: _Operand | float) -> _Operand: # type: ignore[override]
180
+ return self.apply("eq", self, other)
181
+
182
+ def __ne__(self, other: _Operand | float) -> _Operand: # type: ignore[override]
183
+ return self.apply("ne", self, other)
184
+
185
+ def __lt__(self, other: _Operand | float) -> _Operand:
186
+ return self.apply("lt", self, other)
187
+
188
+ def __le__(self, other: _Operand | float) -> _Operand:
189
+ return self.apply("le", self, other)
190
+
191
+ def __gt__(self, other: _Operand | float) -> _Operand:
192
+ return self.apply("gt", self, other)
193
+
194
+ def __ge__(self, other: _Operand | float) -> _Operand:
195
+ return self.apply("ge", self, other)
196
+
197
+
198
+ # conversions
199
+ def imagemath_int(self: _Operand) -> _Operand:
200
+ return _Operand(self.im.convert("I"))
201
+
202
+
203
+ def imagemath_float(self: _Operand) -> _Operand:
204
+ return _Operand(self.im.convert("F"))
205
+
206
+
207
+ # logical
208
+ def imagemath_equal(self: _Operand, other: _Operand | float | None) -> _Operand:
209
+ return self.apply("eq", self, other, mode="I")
210
+
211
+
212
+ def imagemath_notequal(self: _Operand, other: _Operand | float | None) -> _Operand:
213
+ return self.apply("ne", self, other, mode="I")
214
+
215
+
216
+ def imagemath_min(self: _Operand, other: _Operand | float | None) -> _Operand:
217
+ return self.apply("min", self, other)
218
+
219
+
220
+ def imagemath_max(self: _Operand, other: _Operand | float | None) -> _Operand:
221
+ return self.apply("max", self, other)
222
+
223
+
224
+ def imagemath_convert(self: _Operand, mode: str) -> _Operand:
225
+ return _Operand(self.im.convert(mode))
226
+
227
+
228
+ ops = {
229
+ "int": imagemath_int,
230
+ "float": imagemath_float,
231
+ "equal": imagemath_equal,
232
+ "notequal": imagemath_notequal,
233
+ "min": imagemath_min,
234
+ "max": imagemath_max,
235
+ "convert": imagemath_convert,
236
+ }
237
+
238
+
239
+ def lambda_eval(expression: Callable[[dict[str, Any]], Any], **kw: Any) -> Any:
240
+ """
241
+ Returns the result of an image function.
242
+
243
+ :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band
244
+ images, use the :py:meth:`~PIL.Image.Image.split` method or
245
+ :py:func:`~PIL.Image.merge` function.
246
+
247
+ :param expression: A function that receives a dictionary.
248
+ :param **kw: Values to add to the function's dictionary.
249
+ :return: The expression result. This is usually an image object, but can
250
+ also be an integer, a floating point value, or a pixel tuple,
251
+ depending on the expression.
252
+ """
253
+
254
+ args: dict[str, Any] = ops.copy()
255
+ args.update(kw)
256
+ for k, v in args.items():
257
+ if isinstance(v, Image.Image):
258
+ args[k] = _Operand(v)
259
+
260
+ out = expression(args)
261
+ try:
262
+ return out.im
263
+ except AttributeError:
264
+ return out
265
+
266
+
267
+ def unsafe_eval(expression: str, **kw: Any) -> Any:
268
+ """
269
+ Evaluates an image expression. This uses Python's ``eval()`` function to process
270
+ the expression string, and carries the security risks of doing so. It is not
271
+ recommended to process expressions without considering this.
272
+ :py:meth:`~lambda_eval` is a more secure alternative.
273
+
274
+ :py:mod:`~PIL.ImageMath` only supports single-layer images. To process multi-band
275
+ images, use the :py:meth:`~PIL.Image.Image.split` method or
276
+ :py:func:`~PIL.Image.merge` function.
277
+
278
+ :param expression: A string containing a Python-style expression.
279
+ :param **kw: Values to add to the evaluation context.
280
+ :return: The evaluated expression. This is usually an image object, but can
281
+ also be an integer, a floating point value, or a pixel tuple,
282
+ depending on the expression.
283
+ """
284
+
285
+ # build execution namespace
286
+ args: dict[str, Any] = ops.copy()
287
+ for k in kw:
288
+ if "__" in k or hasattr(builtins, k):
289
+ msg = f"'{k}' not allowed"
290
+ raise ValueError(msg)
291
+
292
+ args.update(kw)
293
+ for k, v in args.items():
294
+ if isinstance(v, Image.Image):
295
+ args[k] = _Operand(v)
296
+
297
+ compiled_code = compile(expression, "<string>", "eval")
298
+
299
+ def scan(code: CodeType) -> None:
300
+ for const in code.co_consts:
301
+ if type(const) is type(compiled_code):
302
+ scan(const)
303
+
304
+ for name in code.co_names:
305
+ if name not in args and name != "abs":
306
+ msg = f"'{name}' not allowed"
307
+ raise ValueError(msg)
308
+
309
+ scan(compiled_code)
310
+ out = builtins.eval(expression, None, args)
311
+ try:
312
+ return out.im
313
+ except AttributeError:
314
+ return out
@@ -0,0 +1,85 @@
1
+ #
2
+ # The Python Imaging Library.
3
+ # $Id$
4
+ #
5
+ # standard mode descriptors
6
+ #
7
+ # History:
8
+ # 2006-03-20 fl Added
9
+ #
10
+ # Copyright (c) 2006 by Secret Labs AB.
11
+ # Copyright (c) 2006 by Fredrik Lundh.
12
+ #
13
+ # See the README file for information on usage and redistribution.
14
+ #
15
+ from __future__ import annotations
16
+
17
+ import sys
18
+ from functools import lru_cache
19
+ from typing import NamedTuple
20
+
21
+
22
+ class ModeDescriptor(NamedTuple):
23
+ """Wrapper for mode strings."""
24
+
25
+ mode: str
26
+ bands: tuple[str, ...]
27
+ basemode: str
28
+ basetype: str
29
+ typestr: str
30
+
31
+ def __str__(self) -> str:
32
+ return self.mode
33
+
34
+
35
+ @lru_cache
36
+ def getmode(mode: str) -> ModeDescriptor:
37
+ """Gets a mode descriptor for the given mode."""
38
+ endian = "<" if sys.byteorder == "little" else ">"
39
+
40
+ modes = {
41
+ # core modes
42
+ # Bits need to be extended to bytes
43
+ "1": ("L", "L", ("1",), "|b1"),
44
+ "L": ("L", "L", ("L",), "|u1"),
45
+ "I": ("L", "I", ("I",), f"{endian}i4"),
46
+ "F": ("L", "F", ("F",), f"{endian}f4"),
47
+ "P": ("P", "L", ("P",), "|u1"),
48
+ "RGB": ("RGB", "L", ("R", "G", "B"), "|u1"),
49
+ "RGBX": ("RGB", "L", ("R", "G", "B", "X"), "|u1"),
50
+ "RGBA": ("RGB", "L", ("R", "G", "B", "A"), "|u1"),
51
+ "CMYK": ("RGB", "L", ("C", "M", "Y", "K"), "|u1"),
52
+ "YCbCr": ("RGB", "L", ("Y", "Cb", "Cr"), "|u1"),
53
+ # UNDONE - unsigned |u1i1i1
54
+ "LAB": ("RGB", "L", ("L", "A", "B"), "|u1"),
55
+ "HSV": ("RGB", "L", ("H", "S", "V"), "|u1"),
56
+ # extra experimental modes
57
+ "RGBa": ("RGB", "L", ("R", "G", "B", "a"), "|u1"),
58
+ "LA": ("L", "L", ("L", "A"), "|u1"),
59
+ "La": ("L", "L", ("L", "a"), "|u1"),
60
+ "PA": ("RGB", "L", ("P", "A"), "|u1"),
61
+ }
62
+ if mode in modes:
63
+ base_mode, base_type, bands, type_str = modes[mode]
64
+ return ModeDescriptor(mode, bands, base_mode, base_type, type_str)
65
+
66
+ mapping_modes = {
67
+ # I;16 == I;16L, and I;32 == I;32L
68
+ "I;16": "<u2",
69
+ "I;16S": "<i2",
70
+ "I;16L": "<u2",
71
+ "I;16LS": "<i2",
72
+ "I;16B": ">u2",
73
+ "I;16BS": ">i2",
74
+ "I;16N": f"{endian}u2",
75
+ "I;16NS": f"{endian}i2",
76
+ "I;32": "<u4",
77
+ "I;32B": ">u4",
78
+ "I;32L": "<u4",
79
+ "I;32S": "<i4",
80
+ "I;32BS": ">i4",
81
+ "I;32LS": "<i4",
82
+ }
83
+
84
+ type_str = mapping_modes[mode]
85
+ return ModeDescriptor(mode, ("I",), "L", "L", type_str)