sophhub 0.2.1 → 0.2.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.
- package/package.json +1 -1
- package/skills/compact-context/skill.json +20 -0
- package/skills/compact-context/src/SKILL.md +133 -0
- package/skills/compact-context/src/scripts/check.sh +381 -0
- package/skills/compact-context/src/scripts/set-keep-recent.mjs +1337 -0
- package/skills/compact-context/src/scripts/setup.sh +96 -0
- package/skills/feishu-notes-assistant-universal/skill.json +20 -0
- package/skills/feishu-notes-assistant-universal/src/README.md +55 -0
- package/skills/feishu-notes-assistant-universal/src/SKILL.md +159 -0
- package/skills/feishu-notes-assistant-universal/src/bin/linux-amd64/lark-cli-openclaw +0 -0
- package/skills/feishu-notes-assistant-universal/src/bin/linux-arm64/lark-cli-openclaw +0 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/_resolve_lark_cli.py +58 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_meeting_minutes.py +462 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_notes_crud.py +547 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_notes_crud_test.py +181 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/run_meeting_minutes.py +80 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/run_meeting_minutes.sh +5 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/run_note_crud.py +32 -0
- package/skills/feishu-notes-assistant-universal/src/scripts/run_note_crud.sh +5 -0
- package/skills/image-classify/skill.json +5 -5
- package/skills/image-classify/src/SKILL.md +60 -67
- package/skills/image-classify/src/scripts/face_search.py +400 -15
- package/skills/image-classify/src/scripts/send_dm_message.py +332 -0
- package/skills/md2pdf-converter/skill.json +20 -0
- package/skills/md2pdf-converter/src/SKILL.md +244 -0
- package/skills/md2pdf-converter/src/_meta.json +6 -0
- package/skills/md2pdf-converter/src/scripts/generate_emoji_mapping.py +74 -0
- package/skills/md2pdf-converter/src/scripts/md2pdf-local.sh +291 -0
- package/skills/sophnet-bot-client/skill.json +20 -0
- package/skills/sophnet-bot-client/src/SKILL.md +255 -0
- package/skills/sophnet-bot-client/src/pyproject.toml +13 -0
- package/skills/sophnet-bot-client/src/scripts/__init__.py +0 -0
- package/skills/sophnet-bot-client/src/scripts/bot_client_proxy.py +165 -0
- package/skills/sophnet-bot-client/src/scripts/bot_client_safe.sh +29 -0
- package/skills/sophnet-bot-client/src/scripts/bot_client_setup.py +502 -0
- package/skills/sophnet-bot-client/src/tests/__init__.py +0 -0
- package/skills/sophnet-bot-client/src/tests/test_bot_client_proxy.py +255 -0
- package/skills/sophnet-bot-client/src/tests/test_bot_client_setup.py +679 -0
- package/skills/sophnet-bot-client/src/uv.lock +8 -0
- package/skills/sophnet-docx/skill.json +20 -0
- package/skills/sophnet-docx/src/SKILL.md +463 -0
- package/skills/sophnet-docx/src/package-lock.json +208 -0
- package/skills/sophnet-docx/src/package.json +16 -0
- package/skills/sophnet-docx/src/pyproject.toml +11 -0
- package/skills/sophnet-docx/src/scripts/__init__.py +1 -0
- package/skills/sophnet-docx/src/scripts/accept_changes.py +135 -0
- package/skills/sophnet-docx/src/scripts/comment.py +318 -0
- package/skills/sophnet-docx/src/scripts/ensure_uv_env.sh +68 -0
- package/skills/sophnet-docx/src/scripts/office/helpers/__init__.py +0 -0
- package/skills/sophnet-docx/src/scripts/office/helpers/merge_runs.py +199 -0
- package/skills/sophnet-docx/src/scripts/office/helpers/simplify_redlines.py +197 -0
- package/skills/sophnet-docx/src/scripts/office/pack.py +159 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/sophnet-docx/src/scripts/office/soffice.py +183 -0
- package/skills/sophnet-docx/src/scripts/office/unpack.py +132 -0
- package/skills/sophnet-docx/src/scripts/office/validate.py +111 -0
- package/skills/sophnet-docx/src/scripts/office/validators/__init__.py +15 -0
- package/skills/sophnet-docx/src/scripts/office/validators/base.py +847 -0
- package/skills/sophnet-docx/src/scripts/office/validators/docx.py +446 -0
- package/skills/sophnet-docx/src/scripts/office/validators/pptx.py +275 -0
- package/skills/sophnet-docx/src/scripts/office/validators/redlining.py +247 -0
- package/skills/sophnet-docx/src/scripts/templates/comments.xml +3 -0
- package/skills/sophnet-docx/src/scripts/templates/commentsExtended.xml +3 -0
- package/skills/sophnet-docx/src/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/sophnet-docx/src/scripts/templates/commentsIds.xml +3 -0
- package/skills/sophnet-docx/src/scripts/templates/people.xml +3 -0
- package/skills/sophnet-docx/src/scripts/upload_file.sh +96 -0
- package/skills/sophnet-docx/src/uv.lock +320 -0
- package/skills/sophnet-pdf/skill.json +20 -0
- package/skills/sophnet-pdf/src/SKILL.md +413 -0
- package/skills/sophnet-pdf/src/forms.md +297 -0
- package/skills/sophnet-pdf/src/pyproject.toml +14 -0
- package/skills/sophnet-pdf/src/reference.md +612 -0
- package/skills/sophnet-pdf/src/scripts/check_bounding_boxes.py +65 -0
- package/skills/sophnet-pdf/src/scripts/check_fillable_fields.py +11 -0
- package/skills/sophnet-pdf/src/scripts/convert_pdf_to_images.py +33 -0
- package/skills/sophnet-pdf/src/scripts/create_validation_image.py +37 -0
- package/skills/sophnet-pdf/src/scripts/enhance_tutorial.py +558 -0
- package/skills/sophnet-pdf/src/scripts/ensure_uv_env.sh +68 -0
- package/skills/sophnet-pdf/src/scripts/extract_form_field_info.py +122 -0
- package/skills/sophnet-pdf/src/scripts/extract_form_structure.py +115 -0
- package/skills/sophnet-pdf/src/scripts/extract_pdf_content.py +35 -0
- package/skills/sophnet-pdf/src/scripts/fill_fillable_fields.py +98 -0
- package/skills/sophnet-pdf/src/scripts/fill_pdf_form_with_annotations.py +107 -0
- package/skills/sophnet-pdf/src/scripts/upload_file.sh +88 -0
- package/skills/sophnet-pdf/src/uv.lock +537 -0
- package/skills/sophnet-xlsx/skill.json +20 -0
- package/skills/sophnet-xlsx/src/SKILL.md +399 -0
- package/skills/sophnet-xlsx/src/pyproject.toml +11 -0
- package/skills/sophnet-xlsx/src/scripts/ensure_uv_env.sh +68 -0
- package/skills/sophnet-xlsx/src/scripts/office/helpers/__init__.py +0 -0
- package/skills/sophnet-xlsx/src/scripts/office/helpers/merge_runs.py +199 -0
- package/skills/sophnet-xlsx/src/scripts/office/helpers/simplify_redlines.py +197 -0
- package/skills/sophnet-xlsx/src/scripts/office/pack.py +159 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/sophnet-xlsx/src/scripts/office/soffice.py +183 -0
- package/skills/sophnet-xlsx/src/scripts/office/unpack.py +132 -0
- package/skills/sophnet-xlsx/src/scripts/office/validate.py +111 -0
- package/skills/sophnet-xlsx/src/scripts/office/validators/__init__.py +15 -0
- package/skills/sophnet-xlsx/src/scripts/office/validators/base.py +847 -0
- package/skills/sophnet-xlsx/src/scripts/office/validators/docx.py +446 -0
- package/skills/sophnet-xlsx/src/scripts/office/validators/pptx.py +275 -0
- package/skills/sophnet-xlsx/src/scripts/office/validators/redlining.py +247 -0
- package/skills/sophnet-xlsx/src/scripts/recalc.py +184 -0
- package/skills/sophnet-xlsx/src/scripts/upload_file.sh +96 -0
- package/skills/sophnet-xlsx/src/uv.lock +319 -0
- package/skills/wechat-article-publisher/skill.json +20 -0
- package/skills/wechat-article-publisher/src/SKILL.md +60 -0
- package/skills/wechat-article-publisher/src/config.json +7 -0
- package/skills/wechat-article-publisher/src/pyproject.toml +12 -0
- package/skills/wechat-article-publisher/src/scripts/publish_wechat.py +825 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from pdf2image import convert_from_path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def convert(pdf_path, output_dir, max_dim=1000):
|
|
10
|
+
images = convert_from_path(pdf_path, dpi=200)
|
|
11
|
+
|
|
12
|
+
for i, image in enumerate(images):
|
|
13
|
+
width, height = image.size
|
|
14
|
+
if width > max_dim or height > max_dim:
|
|
15
|
+
scale_factor = min(max_dim / width, max_dim / height)
|
|
16
|
+
new_width = int(width * scale_factor)
|
|
17
|
+
new_height = int(height * scale_factor)
|
|
18
|
+
image = image.resize((new_width, new_height))
|
|
19
|
+
|
|
20
|
+
image_path = os.path.join(output_dir, f"page_{i+1}.png")
|
|
21
|
+
image.save(image_path)
|
|
22
|
+
print(f"Saved page {i+1} as {image_path} (size: {image.size})")
|
|
23
|
+
|
|
24
|
+
print(f"Converted {len(images)} pages to PNG images")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
if len(sys.argv) != 3:
|
|
29
|
+
print("Usage: convert_pdf_to_images.py [input pdf] [output directory]")
|
|
30
|
+
sys.exit(1)
|
|
31
|
+
pdf_path = sys.argv[1]
|
|
32
|
+
output_directory = sys.argv[2]
|
|
33
|
+
convert(pdf_path, output_directory)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from PIL import Image, ImageDraw
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_validation_image(page_number, fields_json_path, input_path, output_path):
|
|
10
|
+
with open(fields_json_path, 'r') as f:
|
|
11
|
+
data = json.load(f)
|
|
12
|
+
|
|
13
|
+
img = Image.open(input_path)
|
|
14
|
+
draw = ImageDraw.Draw(img)
|
|
15
|
+
num_boxes = 0
|
|
16
|
+
|
|
17
|
+
for field in data["form_fields"]:
|
|
18
|
+
if field["page_number"] == page_number:
|
|
19
|
+
entry_box = field['entry_bounding_box']
|
|
20
|
+
label_box = field['label_bounding_box']
|
|
21
|
+
draw.rectangle(entry_box, outline='red', width=2)
|
|
22
|
+
draw.rectangle(label_box, outline='blue', width=2)
|
|
23
|
+
num_boxes += 2
|
|
24
|
+
|
|
25
|
+
img.save(output_path)
|
|
26
|
+
print(f"Created validation image at {output_path} with {num_boxes} bounding boxes")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
if len(sys.argv) != 5:
|
|
31
|
+
print("Usage: create_validation_image.py [page number] [fields.json file] [input image path] [output image path]")
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
page_number = int(sys.argv[1])
|
|
34
|
+
fields_json_path = sys.argv[2]
|
|
35
|
+
input_image_path = sys.argv[3]
|
|
36
|
+
output_image_path = sys.argv[4]
|
|
37
|
+
create_validation_image(page_number, fields_json_path, input_image_path, output_image_path)
|
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Enhance the Image-Edit tutorial PDF with richer content."""
|
|
3
|
+
|
|
4
|
+
from reportlab.lib.pagesizes import A4
|
|
5
|
+
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
6
|
+
from reportlab.lib.units import cm
|
|
7
|
+
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
|
|
8
|
+
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak, Table, TableStyle
|
|
9
|
+
from reportlab.lib import colors
|
|
10
|
+
from reportlab.pdfbase import pdfmetrics
|
|
11
|
+
from reportlab.pdfbase.ttfonts import TTFont
|
|
12
|
+
|
|
13
|
+
# Create output PDF
|
|
14
|
+
output_path = "/Data/shutong.shan/clawd/media/outbound/Image-Edit_教程_增强版.pdf"
|
|
15
|
+
doc = SimpleDocTemplate(
|
|
16
|
+
output_path,
|
|
17
|
+
pagesize=A4,
|
|
18
|
+
rightMargin=2*cm,
|
|
19
|
+
leftMargin=2*cm,
|
|
20
|
+
topMargin=2*cm,
|
|
21
|
+
bottomMargin=2*cm
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Define styles
|
|
25
|
+
styles = getSampleStyleSheet()
|
|
26
|
+
|
|
27
|
+
title_style = ParagraphStyle(
|
|
28
|
+
'Title',
|
|
29
|
+
parent=styles['Title'],
|
|
30
|
+
fontSize=24,
|
|
31
|
+
textColor=colors.darkblue,
|
|
32
|
+
spaceAfter=1*cm,
|
|
33
|
+
alignment=TA_CENTER,
|
|
34
|
+
fontName='Helvetica-Bold'
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
subtitle_style = ParagraphStyle(
|
|
38
|
+
'Subtitle',
|
|
39
|
+
parent=styles['Heading2'],
|
|
40
|
+
fontSize=16,
|
|
41
|
+
textColor=colors.darkgray,
|
|
42
|
+
spaceAfter=0.8*cm,
|
|
43
|
+
alignment=TA_CENTER,
|
|
44
|
+
fontName='Helvetica'
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
heading1_style = ParagraphStyle(
|
|
48
|
+
'Heading1',
|
|
49
|
+
parent=styles['Heading1'],
|
|
50
|
+
fontSize=18,
|
|
51
|
+
textColor=colors.darkblue,
|
|
52
|
+
spaceAfter=0.5*cm,
|
|
53
|
+
spaceBefore=0.5*cm,
|
|
54
|
+
fontName='Helvetica-Bold'
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
heading2_style = ParagraphStyle(
|
|
58
|
+
'Heading2',
|
|
59
|
+
parent=styles['Heading2'],
|
|
60
|
+
fontSize=14,
|
|
61
|
+
textColor=colors.darkgreen,
|
|
62
|
+
spaceAfter=0.3*cm,
|
|
63
|
+
spaceBefore=0.4*cm,
|
|
64
|
+
fontName='Helvetica-Bold'
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
heading3_style = ParagraphStyle(
|
|
68
|
+
'Heading3',
|
|
69
|
+
parent=styles['Heading3'],
|
|
70
|
+
fontSize=12,
|
|
71
|
+
textColor=colors.purple,
|
|
72
|
+
spaceAfter=0.2*cm,
|
|
73
|
+
spaceBefore=0.2*cm,
|
|
74
|
+
fontName='Helvetica-Bold'
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
body_style = ParagraphStyle(
|
|
78
|
+
'Body',
|
|
79
|
+
parent=styles['Normal'],
|
|
80
|
+
fontSize=11,
|
|
81
|
+
spaceAfter=0.3*cm,
|
|
82
|
+
alignment=TA_JUSTIFY,
|
|
83
|
+
fontName='Helvetica',
|
|
84
|
+
leading=16
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
code_style = ParagraphStyle(
|
|
88
|
+
'Code',
|
|
89
|
+
parent=styles['Code'],
|
|
90
|
+
fontSize=10,
|
|
91
|
+
textColor=colors.darkblue,
|
|
92
|
+
fontName='Courier',
|
|
93
|
+
leftIndent=1*cm,
|
|
94
|
+
spaceAfter=0.3*cm
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
note_style = ParagraphStyle(
|
|
98
|
+
'Note',
|
|
99
|
+
parent=styles['Normal'],
|
|
100
|
+
fontSize=10,
|
|
101
|
+
textColor=colors.darkred,
|
|
102
|
+
leftIndent=0.5*cm,
|
|
103
|
+
rightIndent=0.5*cm,
|
|
104
|
+
spaceAfter=0.3*cm,
|
|
105
|
+
fontName='Helvetica-Oblique'
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Build content
|
|
109
|
+
story = []
|
|
110
|
+
|
|
111
|
+
# Title page
|
|
112
|
+
story.append(Paragraph("Image-Edit 教程", title_style))
|
|
113
|
+
story.append(Paragraph("完整的图像编辑技能指南", subtitle_style))
|
|
114
|
+
story.append(Spacer(1, 2*cm))
|
|
115
|
+
|
|
116
|
+
story.append(Paragraph(
|
|
117
|
+
"Image-Edit 是一个强大的图像编辑技能,通过 Sophnet API 实现智能图像处理。本教程将帮助你快速掌握 Image-Edit 的使用方法,包括基础操作、高级技巧和最佳实践。",
|
|
118
|
+
body_style
|
|
119
|
+
))
|
|
120
|
+
|
|
121
|
+
story.append(PageBreak())
|
|
122
|
+
|
|
123
|
+
# Table of Contents
|
|
124
|
+
story.append(Paragraph("目录", heading1_style))
|
|
125
|
+
toc_items = [
|
|
126
|
+
("1. 简介", 3),
|
|
127
|
+
("2. 快速开始", 4),
|
|
128
|
+
("3. 基础操作", 5),
|
|
129
|
+
("4. 高级编辑功能", 6),
|
|
130
|
+
("5. 最佳实践", 7),
|
|
131
|
+
("6. 常见问题", 8),
|
|
132
|
+
("7. 示例代码", 9),
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
toc_data = [['章节', '页码']]
|
|
136
|
+
toc_data.extend(toc_items)
|
|
137
|
+
|
|
138
|
+
toc_table = Table(toc_data, colWidths=[12*cm, 3*cm])
|
|
139
|
+
toc_table.setStyle(TableStyle([
|
|
140
|
+
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
|
|
141
|
+
('FONTSIZE', (0, 0), (-1, 0), 12),
|
|
142
|
+
('BACKGROUND', (0, 0), (-1, 0), colors.lightgrey),
|
|
143
|
+
('TEXTCOLOR', (0, 0), (-1, 0), colors.black),
|
|
144
|
+
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
|
|
145
|
+
('FONTNAME', (0, 1), (-1, -1), 'Helvetica'),
|
|
146
|
+
('FONTSIZE', (0, 1), (-1, -1), 11),
|
|
147
|
+
('GRID', (0, 0), (-1, -1), 1, colors.lightgrey),
|
|
148
|
+
('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.lightblue]),
|
|
149
|
+
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
|
|
150
|
+
('LEFTPADDING', (0, 0), (-1, -1), 12),
|
|
151
|
+
('RIGHTPADDING', (0, 0), (-1, -1), 12),
|
|
152
|
+
('TOPPADDING', (0, 0), (-1, -1), 8),
|
|
153
|
+
('BOTTOMPADDING', (0, 0), (-1, -1), 8),
|
|
154
|
+
]))
|
|
155
|
+
|
|
156
|
+
story.append(toc_table)
|
|
157
|
+
story.append(PageBreak())
|
|
158
|
+
|
|
159
|
+
# Chapter 1: Introduction
|
|
160
|
+
story.append(Paragraph("1. 简介", heading1_style))
|
|
161
|
+
story.append(Paragraph("1.1 什么是 Image-Edit?", heading2_style))
|
|
162
|
+
story.append(Paragraph(
|
|
163
|
+
"Image-Edit 是基于 Sophnet API 的图像编辑技能,支持多种图像处理操作,包括图像到图像的转换、风格迁移、区域编辑、多图像合成等功能。它使用先进的深度学习模型来实现高质量的图像编辑效果。",
|
|
164
|
+
body_style
|
|
165
|
+
))
|
|
166
|
+
|
|
167
|
+
story.append(Paragraph("1.2 核心功能", heading2_style))
|
|
168
|
+
story.append(Paragraph(
|
|
169
|
+
"<b>•</b> 图像风格转换 - 将一张图片的风格应用到另一张图片上<br/>"
|
|
170
|
+
"<b>•</b> 区域编辑 - 精确编辑图片的特定区域<br/>"
|
|
171
|
+
"<b>•</b> 多图像合成 - 将多张图片组合成一幅作品<br/>"
|
|
172
|
+
"<b>•</b> 图像增强 - 改善图片质量,提高清晰度和色彩<br/>"
|
|
173
|
+
"<b>•</b> 背景替换 - 更换或移除图片背景<br/>"
|
|
174
|
+
"<b>•</b> 对象移除/添加 - 智能删除或添加图片中的元素",
|
|
175
|
+
body_style
|
|
176
|
+
))
|
|
177
|
+
|
|
178
|
+
story.append(Paragraph("1.3 系统要求", heading2_style))
|
|
179
|
+
story.append(Paragraph(
|
|
180
|
+
"<b>•</b> Python 3.7 或更高版本<br/>"
|
|
181
|
+
"<b>•</b> Sophnet API 密钥(通过 sophnet-sophon-key 技能配置)<br/>"
|
|
182
|
+
"<b>•</b> 稳定的网络连接(调用远程 API 需要)",
|
|
183
|
+
body_style
|
|
184
|
+
))
|
|
185
|
+
|
|
186
|
+
story.append(PageBreak())
|
|
187
|
+
|
|
188
|
+
# Chapter 2: Quick Start
|
|
189
|
+
story.append(Paragraph("2. 快速开始", heading1_style))
|
|
190
|
+
story.append(Paragraph("2.1 安装依赖", heading2_style))
|
|
191
|
+
story.append(Paragraph(
|
|
192
|
+
"首先确保已安装 sophnet-skill-installer 技能,然后使用以下命令安装 Image-Edit 相关技能:",
|
|
193
|
+
body_style
|
|
194
|
+
))
|
|
195
|
+
story.append(Paragraph(
|
|
196
|
+
"clawhub install sophnet-image-edit",
|
|
197
|
+
code_style
|
|
198
|
+
))
|
|
199
|
+
story.append(Paragraph(
|
|
200
|
+
"这将自动安装所有必要的依赖和配置文件。",
|
|
201
|
+
body_style
|
|
202
|
+
))
|
|
203
|
+
|
|
204
|
+
story.append(Paragraph("2.2 配置 API 密钥", heading2_style))
|
|
205
|
+
story.append(Paragraph(
|
|
206
|
+
"在使用 Image-Edit 之前,需要配置 Sophnet API 密钥:",
|
|
207
|
+
body_style
|
|
208
|
+
))
|
|
209
|
+
story.append(Paragraph(
|
|
210
|
+
"1. 确保已设置 SOPH_API_KEY 环境变量<br/>"
|
|
211
|
+
"2. 或者在 Moltbot 配置文件中添加 API 密钥配置<br/>"
|
|
212
|
+
"3. sophnet-sophon-key 技能会自动检测并引导你完成配置",
|
|
213
|
+
body_style
|
|
214
|
+
))
|
|
215
|
+
|
|
216
|
+
story.append(Paragraph("2.3 基本使用流程", heading2_style))
|
|
217
|
+
story.append(Paragraph(
|
|
218
|
+
"Image-Edit 的基本使用流程如下:",
|
|
219
|
+
body_style
|
|
220
|
+
))
|
|
221
|
+
story.append(Paragraph(
|
|
222
|
+
"1. <b>输入图片</b> - 准备需要编辑的原始图片(支持本地文件或 URL)<br/>"
|
|
223
|
+
"2. <b>编辑指令</b> - 提供清晰的编辑指令或提示词<br/>"
|
|
224
|
+
"3. <b>处理图像</b> - 调用 Image-Edit API 进行处理<br/>"
|
|
225
|
+
"4. <b>获取结果</b> - 接收并保存编辑后的图片<br/>"
|
|
226
|
+
"5. <b>迭代优化</b> - 如有需要,根据结果调整参数重新处理",
|
|
227
|
+
body_style
|
|
228
|
+
))
|
|
229
|
+
|
|
230
|
+
story.append(PageBreak())
|
|
231
|
+
|
|
232
|
+
# Chapter 3: Basic Operations
|
|
233
|
+
story.append(Paragraph("3. 基础操作", heading1_style))
|
|
234
|
+
story.append(Paragraph("3.1 单张图片编辑", heading2_style))
|
|
235
|
+
story.append(Paragraph(
|
|
236
|
+
"最简单的用法是对单张图片进行编辑。提供一张图片和编辑描述:",
|
|
237
|
+
body_style
|
|
238
|
+
))
|
|
239
|
+
story.append(Paragraph(
|
|
240
|
+
"示例:将一张照片转换为油画风格",
|
|
241
|
+
body_style
|
|
242
|
+
))
|
|
243
|
+
story.append(Paragraph(
|
|
244
|
+
"<b>输入图片:</b> portrait.jpg<br/>"
|
|
245
|
+
"<b>编辑指令:</b> 将这张照片转换为梵高风格的油画<br/>"
|
|
246
|
+
"<b>处理结果:</b> 获得 oil_painting_style.jpg",
|
|
247
|
+
body_style
|
|
248
|
+
))
|
|
249
|
+
|
|
250
|
+
story.append(Paragraph("3.2 区域编辑", heading2_style))
|
|
251
|
+
story.append(Paragraph(
|
|
252
|
+
"区域编辑允许你精确控制图片的特定部分进行修改:",
|
|
253
|
+
body_style
|
|
254
|
+
))
|
|
255
|
+
story.append(Paragraph(
|
|
256
|
+
"<b>示例场景:</b><br/>"
|
|
257
|
+
"• 修改人物发色<br/>"
|
|
258
|
+
"• 更换衣服颜色<br/>"
|
|
259
|
+
"• 调整背景亮度<br/>"
|
|
260
|
+
"• 移除或添加特定对象",
|
|
261
|
+
body_style
|
|
262
|
+
))
|
|
263
|
+
story.append(Paragraph(
|
|
264
|
+
"提示:提供精确的区域描述可以大大提高编辑准确性。",
|
|
265
|
+
note_style
|
|
266
|
+
))
|
|
267
|
+
|
|
268
|
+
story.append(Paragraph("3.3 图片风格迁移", heading3_style))
|
|
269
|
+
story.append(Paragraph(
|
|
270
|
+
"使用一张图片的风格来处理另一张图片:",
|
|
271
|
+
body_style
|
|
272
|
+
))
|
|
273
|
+
story.append(Paragraph(
|
|
274
|
+
"<b>参考图片:</b> 梵高《星空》<br/>"
|
|
275
|
+
"<b>目标图片:</b> 你的城市照片<br/>"
|
|
276
|
+
"<b>效果:</b> 城市照片呈现出《星空》的笔触和色彩风格",
|
|
277
|
+
body_style
|
|
278
|
+
))
|
|
279
|
+
|
|
280
|
+
story.append(PageBreak())
|
|
281
|
+
|
|
282
|
+
# Chapter 4: Advanced Features
|
|
283
|
+
story.append(Paragraph("4. 高级编辑功能", heading1_style))
|
|
284
|
+
story.append(Paragraph("4.1 多图像编辑", heading2_style))
|
|
285
|
+
story.append(Paragraph(
|
|
286
|
+
"Image-Edit 支持同时处理多张图片,适用于复杂的合成任务:",
|
|
287
|
+
body_style
|
|
288
|
+
))
|
|
289
|
+
story.append(Paragraph(
|
|
290
|
+
"<b>典型应用:</b><br/>"
|
|
291
|
+
"• 换脸技术<br/>"
|
|
292
|
+
"• 服装试穿<br/>"
|
|
293
|
+
"• 场景合成<br/>"
|
|
294
|
+
"• 多人图像组合",
|
|
295
|
+
body_style
|
|
296
|
+
))
|
|
297
|
+
|
|
298
|
+
story.append(Paragraph("4.2 批量处理", heading2_style))
|
|
299
|
+
story.append(Paragraph(
|
|
300
|
+
"对于需要处理大量相似图片的场景,可以使用批量处理功能:",
|
|
301
|
+
body_style
|
|
302
|
+
))
|
|
303
|
+
story.append(Paragraph(
|
|
304
|
+
"• 统一风格转换<br/>"
|
|
305
|
+
"• 批量背景移除<br/>"
|
|
306
|
+
"• 批量质量增强<br/>"
|
|
307
|
+
"• 批量水印添加",
|
|
308
|
+
body_style
|
|
309
|
+
))
|
|
310
|
+
|
|
311
|
+
story.append(Paragraph("4.3 高级控制参数", heading2_style))
|
|
312
|
+
story.append(Paragraph(
|
|
313
|
+
"Image-Edit 支持多种高级参数来控制编辑效果:",
|
|
314
|
+
body_style
|
|
315
|
+
))
|
|
316
|
+
|
|
317
|
+
advanced_params = [
|
|
318
|
+
['参数', '说明', '示例值'],
|
|
319
|
+
['strength', '编辑强度', '0.1-1.0'],
|
|
320
|
+
['steps', '处理步数', '20-50'],
|
|
321
|
+
['guidance_scale', '提示词引导强度', '7.5-15.0'],
|
|
322
|
+
['seed', '随机种子(复现结果)', '42'],
|
|
323
|
+
['negative_prompt', '负面提示词', 'blur, low quality'],
|
|
324
|
+
]
|
|
325
|
+
|
|
326
|
+
params_table = Table(advanced_params, colWidths=[4*cm, 5*cm, 6*cm])
|
|
327
|
+
params_table.setStyle(TableStyle([
|
|
328
|
+
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
|
|
329
|
+
('FONTSIZE', (0, 0), (-1, 0), 11),
|
|
330
|
+
('BACKGROUND', (0, 0), (-1, 0), colors.lightblue),
|
|
331
|
+
('GRID', (0, 0), (-1, -1), 1, colors.lightgrey),
|
|
332
|
+
('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.lightgrey]),
|
|
333
|
+
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
|
|
334
|
+
('LEFTPADDING', (0, 0), (-1, -1), 8),
|
|
335
|
+
('RIGHTPADDING', (0, 0), (-1, -1), 8),
|
|
336
|
+
('TOPPADDING', (0, 0), (-1, -1), 6),
|
|
337
|
+
('BOTTOMPADDING', (0, 0), (-1, -1), 6),
|
|
338
|
+
]))
|
|
339
|
+
|
|
340
|
+
story.append(params_table)
|
|
341
|
+
|
|
342
|
+
story.append(PageBreak())
|
|
343
|
+
|
|
344
|
+
# Chapter 5: Best Practices
|
|
345
|
+
story.append(Paragraph("5. 最佳实践", heading1_style))
|
|
346
|
+
story.append(Paragraph("5.1 提示词编写技巧", heading2_style))
|
|
347
|
+
story.append(Paragraph(
|
|
348
|
+
"良好的提示词是获得理想效果的关键。以下是一些实用技巧:",
|
|
349
|
+
body_style
|
|
350
|
+
))
|
|
351
|
+
|
|
352
|
+
tips = [
|
|
353
|
+
("明确具体", "避免模糊的描述,使用具体的形容词和名词"),
|
|
354
|
+
("使用正向语言", "描述你想要的效果,而不是你不想要的"),
|
|
355
|
+
("参考风格", "提及知名艺术家或艺术风格可以提高准确性"),
|
|
356
|
+
("控制长度", "提示词不宜过长或过短,通常50-200字效果最佳"),
|
|
357
|
+
("迭代优化", "根据结果调整提示词,逐步接近理想效果"),
|
|
358
|
+
]
|
|
359
|
+
|
|
360
|
+
for i, (tip, desc) in enumerate(tips, 1):
|
|
361
|
+
story.append(Paragraph(f"5.1.{i} {tip}", heading3_style))
|
|
362
|
+
story.append(Paragraph(desc, body_style))
|
|
363
|
+
|
|
364
|
+
story.append(Paragraph("5.2 图片质量要求", heading2_style))
|
|
365
|
+
story.append(Paragraph(
|
|
366
|
+
"为了获得最佳的编辑效果,输入图片应满足以下要求:",
|
|
367
|
+
body_style
|
|
368
|
+
))
|
|
369
|
+
story.append(Paragraph(
|
|
370
|
+
"<b>•</b> <b>分辨率:</b> 建议 512x512 或更高<br/>"
|
|
371
|
+
"<b>•</b> <b>格式:</b> 支持 JPEG、PNG、WebP 等常见格式<br/>"
|
|
372
|
+
"<b>•</b> <b>文件大小:</b> 建议不超过 10MB<br/>"
|
|
373
|
+
"<b>•</b> <b>清晰度:</b> 避免过度模糊或压缩的图片<br/>"
|
|
374
|
+
"<b>•</b> <b>对比度:</b> 适当的对比度有助于理解图片内容",
|
|
375
|
+
body_style
|
|
376
|
+
))
|
|
377
|
+
|
|
378
|
+
story.append(Paragraph("5.3 性能优化", heading2_style))
|
|
379
|
+
story.append(Paragraph(
|
|
380
|
+
"优化处理效率的建议:",
|
|
381
|
+
body_style
|
|
382
|
+
))
|
|
383
|
+
story.append(Paragraph(
|
|
384
|
+
"<b>•</b> 批量处理时使用合理的并发数<br/>"
|
|
385
|
+
"<b>•</b> 适当调整 steps 参数以平衡质量和速度<br/>"
|
|
386
|
+
"<b>•</b> 缓存常用的参考图片<br/>"
|
|
387
|
+
"<b>•</b> 使用相同 seed 以便复现和调试",
|
|
388
|
+
body_style
|
|
389
|
+
))
|
|
390
|
+
|
|
391
|
+
story.append(PageBreak())
|
|
392
|
+
|
|
393
|
+
# Chapter 6: FAQ
|
|
394
|
+
story.append(Paragraph("6. 常见问题", heading1_style))
|
|
395
|
+
|
|
396
|
+
faqs = [
|
|
397
|
+
(
|
|
398
|
+
"Q: 为什么我的编辑效果不理想?",
|
|
399
|
+
"A: 尝试改进提示词的描述性,使用更具体的形容词和艺术风格参考。同时检查输入图片的清晰度和质量。"
|
|
400
|
+
),
|
|
401
|
+
(
|
|
402
|
+
"Q: 处理速度很慢怎么办?",
|
|
403
|
+
"A: 可以减少 steps 参数值,或降低图片分辨率。对于大批量处理,考虑使用队列系统。"
|
|
404
|
+
),
|
|
405
|
+
(
|
|
406
|
+
"Q: 如何保持图片的某些部分不变?",
|
|
407
|
+
"A: 使用区域编辑功能,明确指定需要编辑的区域,其他部分将保持不变。"
|
|
408
|
+
),
|
|
409
|
+
(
|
|
410
|
+
"Q: 可以撤销编辑操作吗?",
|
|
411
|
+
"A: 编辑完成后无法撤销,建议在重要操作前保存原始图片的备份。"
|
|
412
|
+
),
|
|
413
|
+
(
|
|
414
|
+
"Q: 支持哪些图片格式?",
|
|
415
|
+
"A: 支持 JPEG、PNG、WebP、GIF 等常见格式,推荐使用 PNG 以获得最佳质量。"
|
|
416
|
+
),
|
|
417
|
+
(
|
|
418
|
+
"Q: API 调用失败怎么办?",
|
|
419
|
+
"A: 检查网络连接和 API 密钥配置,查看错误信息并根据错误类型采取相应措施。"
|
|
420
|
+
),
|
|
421
|
+
]
|
|
422
|
+
|
|
423
|
+
for i, (q, a) in enumerate(faqs, 1):
|
|
424
|
+
story.append(Paragraph(f"6.{i} {q}", heading2_style))
|
|
425
|
+
story.append(Paragraph(a, body_style))
|
|
426
|
+
story.append(Spacer(1, 0.3*cm))
|
|
427
|
+
|
|
428
|
+
story.append(PageBreak())
|
|
429
|
+
|
|
430
|
+
# Chapter 7: Example Code
|
|
431
|
+
story.append(Paragraph("7. 示例代码", heading1_style))
|
|
432
|
+
story.append(Paragraph("7.1 基础编辑示例", heading2_style))
|
|
433
|
+
story.append(Paragraph(
|
|
434
|
+
"以下是一个简单的 Python 示例,展示如何使用 Image-Edit 进行基础编辑:",
|
|
435
|
+
body_style
|
|
436
|
+
))
|
|
437
|
+
|
|
438
|
+
example1 = '''
|
|
439
|
+
# 导入 Image-Edit 技能
|
|
440
|
+
from skills import image_edit
|
|
441
|
+
|
|
442
|
+
# 准备输入图片
|
|
443
|
+
input_image = "portrait.jpg"
|
|
444
|
+
|
|
445
|
+
# 编辑指令
|
|
446
|
+
prompt = "将这张照片转换为梵高风格的油画,使用鲜艳的色彩和厚重的笔触"
|
|
447
|
+
|
|
448
|
+
# 调用 Image-Edit
|
|
449
|
+
result = image_edit.edit(
|
|
450
|
+
image_path=input_image,
|
|
451
|
+
prompt=prompt,
|
|
452
|
+
strength=0.8,
|
|
453
|
+
steps=30
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
# 保存结果
|
|
457
|
+
result.save("oil_painting_portrait.jpg")
|
|
458
|
+
print("编辑完成!")
|
|
459
|
+
'''
|
|
460
|
+
story.append(Paragraph(example1, code_style))
|
|
461
|
+
|
|
462
|
+
story.append(Paragraph("7.2 风格迁移示例", heading2_style))
|
|
463
|
+
style_example = '''
|
|
464
|
+
# 风格迁移:应用艺术风格到照片
|
|
465
|
+
result = image_edit.style_transfer(
|
|
466
|
+
source_image="city_photo.jpg",
|
|
467
|
+
reference_image="starry_night.jpg",
|
|
468
|
+
prompt="将城市照片转换为梵高《星空》的艺术风格",
|
|
469
|
+
strength=0.7,
|
|
470
|
+
guidance_scale=10.0
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
result.save("starry_night_city.jpg")
|
|
474
|
+
'''
|
|
475
|
+
story.append(Paragraph(style_example, code_style))
|
|
476
|
+
|
|
477
|
+
story.append(Paragraph("7.3 区域编辑示例", heading2_style))
|
|
478
|
+
region_example = '''
|
|
479
|
+
# 区域编辑:修改人物发色
|
|
480
|
+
result = image_edit.edit_region(
|
|
481
|
+
image_path="portrait.jpg",
|
|
482
|
+
region="人物的头发",
|
|
483
|
+
prompt="将头发颜色改为栗棕色,保持自然的发丝质感",
|
|
484
|
+
strength=0.6
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
result.save("new_hair_color.jpg")
|
|
488
|
+
'''
|
|
489
|
+
story.append(Paragraph(region_example, code_style))
|
|
490
|
+
|
|
491
|
+
story.append(Spacer(1, 1*cm))
|
|
492
|
+
story.append(Paragraph("7.4 批量处理示例", heading2_style))
|
|
493
|
+
batch_example = '''
|
|
494
|
+
# 批量处理:统一风格转换
|
|
495
|
+
import os
|
|
496
|
+
|
|
497
|
+
input_dir = "photos/"
|
|
498
|
+
output_dir = "stylized/"
|
|
499
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
500
|
+
|
|
501
|
+
for filename in os.listdir(input_dir):
|
|
502
|
+
if filename.endswith(('.jpg', '.png')):
|
|
503
|
+
input_path = os.path.join(input_dir, filename)
|
|
504
|
+
output_path = os.path.join(output_dir, f"stylized_{filename}")
|
|
505
|
+
|
|
506
|
+
result = image_edit.edit(
|
|
507
|
+
image_path=input_path,
|
|
508
|
+
prompt="转换为油画风格,使用印象派技法",
|
|
509
|
+
strength=0.8,
|
|
510
|
+
steps=25
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
result.save(output_path)
|
|
514
|
+
print(f"已处理: {filename}")
|
|
515
|
+
'''
|
|
516
|
+
story.append(Paragraph(batch_example, code_style))
|
|
517
|
+
|
|
518
|
+
story.append(PageBreak())
|
|
519
|
+
|
|
520
|
+
# Appendix and Conclusion
|
|
521
|
+
story.append(Paragraph("附录", heading1_style))
|
|
522
|
+
story.append(Paragraph("A. 相关技能", heading2_style))
|
|
523
|
+
story.append(Paragraph(
|
|
524
|
+
"<b>•</b> sophnet-image-generate - 从文本生成图像<br/>"
|
|
525
|
+
"<b>•</b> sophnet-image-ocr - 从图像中提取文字<br/>"
|
|
526
|
+
"<b>•</b> sophnet-smart-image-loader - 智能图像加载器<br/>"
|
|
527
|
+
"<b>•</b> sophnet-sophon-key - Sophnet API 密钥管理",
|
|
528
|
+
body_style
|
|
529
|
+
))
|
|
530
|
+
|
|
531
|
+
story.append(Paragraph("B. 参考资料", heading2_style))
|
|
532
|
+
story.append(Paragraph(
|
|
533
|
+
"<b>•</b> Sophnet API 文档<br/>"
|
|
534
|
+
"<b>•</b> Image-Edit GitHub 仓库<br/>"
|
|
535
|
+
"<b>•</b> OpenClaw 技能中心 (clawhub.com)",
|
|
536
|
+
body_style
|
|
537
|
+
))
|
|
538
|
+
|
|
539
|
+
story.append(Spacer(1, 1*cm))
|
|
540
|
+
story.append(Paragraph("结语", heading1_style))
|
|
541
|
+
story.append(Paragraph(
|
|
542
|
+
"本教程涵盖了 Image-Edit 技能的核心功能和最佳实践。通过掌握这些知识和技巧,你可以充分发挥 Image-Edit 的强大功能,创造出令人惊艳的图像作品。",
|
|
543
|
+
body_style
|
|
544
|
+
))
|
|
545
|
+
story.append(Paragraph(
|
|
546
|
+
"如有任何问题或建议,欢迎通过社区反馈渠道与我们联系。祝你在图像编辑的旅程中取得丰硕成果!",
|
|
547
|
+
body_style
|
|
548
|
+
))
|
|
549
|
+
story.append(Spacer(1, 0.5*cm))
|
|
550
|
+
story.append(Paragraph(
|
|
551
|
+
"© 2026 Image-Edit 教程 | 基于 OpenClaw 技能系统",
|
|
552
|
+
note_style
|
|
553
|
+
))
|
|
554
|
+
|
|
555
|
+
# Build the PDF
|
|
556
|
+
print("正在构建增强版 PDF...")
|
|
557
|
+
doc.build(story)
|
|
558
|
+
print(f"✓ 增强版 PDF 已创建: {output_path}")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
6
|
+
VENV_PYTHON="$SKILL_DIR/.venv/bin/python"
|
|
7
|
+
QUIET=false
|
|
8
|
+
FORCE_SYNC=false
|
|
9
|
+
|
|
10
|
+
usage() {
|
|
11
|
+
cat <<'USAGE'
|
|
12
|
+
Usage:
|
|
13
|
+
bash ensure_uv_env.sh [options]
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--quiet Reduce non-error output.
|
|
17
|
+
--force-sync Force uv sync even when .venv already exists.
|
|
18
|
+
USAGE
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
log() {
|
|
22
|
+
if [[ "$QUIET" != true ]]; then
|
|
23
|
+
echo "$1" >&2
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
while [[ $# -gt 0 ]]; do
|
|
28
|
+
case "$1" in
|
|
29
|
+
--quiet)
|
|
30
|
+
QUIET=true
|
|
31
|
+
shift
|
|
32
|
+
;;
|
|
33
|
+
--force-sync)
|
|
34
|
+
FORCE_SYNC=true
|
|
35
|
+
shift
|
|
36
|
+
;;
|
|
37
|
+
-h|--help)
|
|
38
|
+
usage
|
|
39
|
+
exit 0
|
|
40
|
+
;;
|
|
41
|
+
*)
|
|
42
|
+
echo "Unknown argument: $1" >&2
|
|
43
|
+
usage
|
|
44
|
+
exit 1
|
|
45
|
+
;;
|
|
46
|
+
esac
|
|
47
|
+
done
|
|
48
|
+
|
|
49
|
+
if ! command -v uv >/dev/null 2>&1; then
|
|
50
|
+
echo "Error: uv is required but not found." >&2
|
|
51
|
+
echo "Install uv first: https://docs.astral.sh/uv/getting-started/installation/" >&2
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
need_sync=false
|
|
56
|
+
|
|
57
|
+
if [[ "$FORCE_SYNC" == true || ! -x "$VENV_PYTHON" ]]; then
|
|
58
|
+
need_sync=true
|
|
59
|
+
elif ! "$VENV_PYTHON" -c 'import pypdf, pdfplumber, PIL, pdf2image, reportlab' >/dev/null 2>&1; then
|
|
60
|
+
need_sync=true
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
if [[ "$need_sync" == true ]]; then
|
|
64
|
+
log "Syncing uv environment at $SKILL_DIR/.venv"
|
|
65
|
+
uv sync --project "$SKILL_DIR" --no-dev
|
|
66
|
+
else
|
|
67
|
+
log "uv environment already ready: $SKILL_DIR/.venv"
|
|
68
|
+
fi
|