clipboard-img-2-gif 0.1.0__tar.gz
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.
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: clipboard-img-2-gif
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Converts clipboard images to GIF, saves them temporarily, and copies them back as a file object.
|
|
5
|
+
Home-page: https://github.com/tgalpha/clipboard-img-2-gif
|
|
6
|
+
Author: tgalpha
|
|
7
|
+
Author-email: tanalpha.zhy@gmail.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Requires-Dist: pillow (>=11.0.0,<12.0.0)
|
|
12
|
+
Requires-Dist: pyperclip (>=1.9.0,<2.0.0)
|
|
13
|
+
Requires-Dist: pywin32 (>=308,<309)
|
|
14
|
+
Project-URL: Repository, https://github.com/tgalpha/clipboard-img-2-gif
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
## clipboard-img-2-gif
|
|
18
|
+
Converts clipboard images to GIF, saves them temporarily, and copies them back as a file object.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "clipboard-img-2-gif"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Converts clipboard images to GIF, saves them temporarily, and copies them back as a file object."
|
|
5
|
+
authors = ["tgalpha <tanalpha.zhy@gmail.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
packages = [{ include = "clipboard_img_2_gif", from = "src" }]
|
|
8
|
+
|
|
9
|
+
repository = "https://github.com/tgalpha/clipboard-img-2-gif"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
python = "^3.11"
|
|
13
|
+
pillow = "^11.0.0"
|
|
14
|
+
pyperclip = "^1.9.0"
|
|
15
|
+
pywin32 = "^308"
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|
|
20
|
+
|
|
21
|
+
[tool.poetry.scripts]
|
|
22
|
+
i2g = "clipboard_img_2_gif.core:main"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
from PIL import ImageGrab, Image
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_clipboard_image_or_path():
|
|
7
|
+
"""Retrieve image data or image path from the clipboard."""
|
|
8
|
+
image = ImageGrab.grabclipboard()
|
|
9
|
+
if isinstance(image, Image.Image):
|
|
10
|
+
return image, None
|
|
11
|
+
elif isinstance(image, list) and os.path.isfile(image[0]):
|
|
12
|
+
# Process only first file in list
|
|
13
|
+
return None, image[0]
|
|
14
|
+
return None, None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def save_as_gif(image, path):
|
|
18
|
+
"""Save the provided image to the specified path in GIF format."""
|
|
19
|
+
width, height = image.size
|
|
20
|
+
width_height_size_limit = 500
|
|
21
|
+
if max(width, height) > width_height_size_limit:
|
|
22
|
+
scaling = width_height_size_limit / max(width, height)
|
|
23
|
+
image = image.resize((int(width * scaling), int(height * scaling)))
|
|
24
|
+
image = image.convert("RGB")
|
|
25
|
+
image.save(path, format="GIF")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def copy_to_clipboard(filepath):
|
|
29
|
+
"""Copy the specified file as a file object to the clipboard."""
|
|
30
|
+
command = f"powershell Set-Clipboard -LiteralPath {filepath}"
|
|
31
|
+
os.system(command)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main():
|
|
35
|
+
image, path = get_clipboard_image_or_path()
|
|
36
|
+
if not image and not path:
|
|
37
|
+
print("No image or image file path found in clipboard.")
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
if path:
|
|
41
|
+
image = Image.open(path)
|
|
42
|
+
|
|
43
|
+
# Convert and save to temporary directory
|
|
44
|
+
temp_dir = tempfile.gettempdir()
|
|
45
|
+
gif_path = os.path.join(temp_dir, "converted.gif")
|
|
46
|
+
save_as_gif(image, gif_path)
|
|
47
|
+
|
|
48
|
+
# Copy GIF back to clipboard
|
|
49
|
+
copy_to_clipboard(gif_path)
|
|
50
|
+
print(f"GIF saved to {gif_path} and copied back to clipboard.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
main()
|