imglib2 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.
- imglib2-0.1.0/LICENSE +0 -0
- imglib2-0.1.0/PKG-INFO +10 -0
- imglib2-0.1.0/README.md +2 -0
- imglib2-0.1.0/pyproject.toml +18 -0
- imglib2-0.1.0/src/imglib2/__init__.py +4 -0
- imglib2-0.1.0/src/imglib2/draw.py +22 -0
- imglib2-0.1.0/src/imglib2/generate.py +14 -0
imglib2-0.1.0/LICENSE
ADDED
|
File without changes
|
imglib2-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: imglib2
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Библиотека для создания изображений
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Requires-Dist: diffusers>=0.25.0
|
|
8
|
+
Requires-Dist: pillow>=10.0.0
|
|
9
|
+
Requires-Dist: torch>=2.1.0
|
|
10
|
+
Requires-Dist: transformers>=4.35.0
|
imglib2-0.1.0/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "imglib2"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Библиотека для создания изображений"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"pillow>=10.0.0",
|
|
12
|
+
"diffusers>=0.25.0",
|
|
13
|
+
"torch>=2.1.0",
|
|
14
|
+
"transformers>=4.35.0"
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/imglib2"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
2
|
+
|
|
3
|
+
def draw_rectangle(width: int, height: int, color: str = "blue", rect: tuple[int,int,int,int]|None = None) -> Image.Image:
|
|
4
|
+
img = Image.new("RGB", (width, height), "white")
|
|
5
|
+
draw = ImageDraw.Draw(img)
|
|
6
|
+
box = rect or (50, 50, width - 50, height - 50)
|
|
7
|
+
draw.rectangle(box, fill=color, outline="black", width=3)
|
|
8
|
+
return img
|
|
9
|
+
|
|
10
|
+
def draw_text(width: int, height: int, text: str, font_size: int = 40) -> Image.Image:
|
|
11
|
+
img = Image.new("RGB", (width, height), "white")
|
|
12
|
+
draw = ImageDraw.Draw(img)
|
|
13
|
+
# fallback если шрифт не найден
|
|
14
|
+
try:
|
|
15
|
+
font = ImageFont.truetype("DejaVuSans.ttf", font_size)
|
|
16
|
+
except OSError:
|
|
17
|
+
font = ImageFont.load_default()
|
|
18
|
+
tw, th = draw.textsize(text, font=font) if hasattr(draw, "textsize") else draw.textbbox((0,0), text, font=font)[2:]
|
|
19
|
+
x = (width - tw) // 2
|
|
20
|
+
y = (height - th) // 2
|
|
21
|
+
draw.text((x, y), text, fill="black", font=font)
|
|
22
|
+
return img
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
def generate_image(prompt: str, width: int = 512, height: int = 512, seed: Optional[int] = None) -> bytes:
|
|
4
|
+
"""
|
|
5
|
+
Заглушка: в реальной реализации здесь будет вызов Stable Diffusion через diffusers.
|
|
6
|
+
Возвращает PNG-байты.
|
|
7
|
+
"""
|
|
8
|
+
# Пример: вернуть простое изображение вместо реальной генерации
|
|
9
|
+
from .draw import draw_text
|
|
10
|
+
img = draw_text(width, height, prompt)
|
|
11
|
+
from io import BytesIO
|
|
12
|
+
buf = BytesIO()
|
|
13
|
+
img.save(buf, format="PNG")
|
|
14
|
+
return buf.getvalue()
|