Extract the 5 most visually interesting detail regions from a large image, crop them as squares, display them in the chat (2 per row), and save them as downloadable files.
Look carefully at the uploaded image. Identify the 5 most interesting regions based on:
⚠️ Signature rule: If a painter's signature is visible anywhere in the image, it must always be one of the 5 highlights. Center the crop precisely on the signature so it is fully visible and not cut off.
⚠️ Strict 1:1 square-fit rule: Every highlight must be a subject that naturally fills a square frame. Before selecting a region, ask: "Does this subject fit well into a square?"
For each region, record:
Use the bash_tool + Python to:
/mnt/user-data/uploads/save_crop helper below — it handles edge cases automatically/mnt/user-data/outputs/highlight_1.jpg … highlight_5.jpgChoosing the half-size: Claude decides per region:
Edge case — subject at image border: If the desired crop extends beyond the image boundary, save_crop takes whatever image content is available and places it centered on a white square canvas (side = longest available side). This keeps the result square and clean with no distortion.
from PIL import Image
import os
img = Image.open("/mnt/user-data/uploads/IMAGE_FILENAME")
w, h = img.size
def save_crop(img, w, h, cx, cy, half, path):
x1 = max(0, cx - half)
x2 = min(w, cx + half)
y1 = max(0, cy - half)
y2 = min(h, cy + half)
rect_w = x2 - x1
rect_h = y2 - y1
crop = img.crop((x1, y1, x2, y2))
if rect_w == rect_h:
# Already square — save directly
crop.save(path, quality=92)
else:
# Place on white square canvas, centered horizontally and vertically
canvas_size = max(rect_w, rect_h)
canvas = Image.new("RGB", (canvas_size, canvas_size), (255, 255, 255))
paste_x = (canvas_size - rect_w) // 2
paste_y = (canvas_size - rect_h) // 2
canvas.paste(crop, (paste_x, paste_y))
canvas.save(path, quality=92)
# Define crops by CENTER point (cx, cy) and half-size
crops = [
# (label, cx, cy, half)
("highlight_1", cx1, cy1, half1),
("highlight_2", cx2, cy2, half2),
("highlight_3", cx3, cy3, half3),
("highlight_4", cx4, cy4, half4),
("highlight_5", cx5, cy5, half5),
]
os.makedirs("/mnt/user-data/outputs", exist_ok=True)
for label, cx, cy, half in crops:
save_crop(img, w, h, cx, cy, half, f"/mnt/user-data/outputs/{label}.jpg")
print("Done")
After saving, use present_files to make all 5 crops downloadable.
Then write a short markdown summary:
## 🎨 5 Highlights aus dem Bild
**1. [Label]** – [Erklärung warum interessant]
**2. [Label]** – ...
...
Show the crops 2 per row by presenting them via present_files and listing them clearly with their labels. Users can download each file individually.
Ask the user: "Soll ich andere Bereiche auswählen, oder die Größe der Crops anpassen?"
pip install Pillow --break-system-packages共 1 个版本