Skip to content

Image Processing

Resize, crop, compress, convert, OCR, QR codes, and watermarks.

9 modules

ModuleDescription
壓縮圖片壓縮圖片以減少檔案大小同時保持品質
轉換圖片將圖片轉換為不同格式(PNG、JPEG、WEBP 等)
裁剪圖片裁剪圖片到指定座標
下載圖片從網址下載圖片到本機檔案
OCR 提取文字使用 OCR 從圖片中提取文字
產生 QR Code從文字、網址或資料產生 QR Code
調整圖片大小使用各種演算法將圖片調整為指定尺寸
旋轉圖片將圖片旋轉指定角度
新增浮水印為圖片新增文字或圖片浮水印

Modules

壓縮圖片

image.compress

壓縮圖片以減少檔案大小同時保持品質

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-Path to the input image file
output_pathstringNo-Path where the processed image will be saved
qualitynumberNo85Quality level (1-100, higher is better)
optimizebooleanNoTrueApply additional optimization
max_size_kbnumberNo-Target maximum file size in KB
formatselect (png, jpeg, webp, gif, bmp, tiff)NopngOutput image format

Output:

FieldTypeDescription
output_pathstring壓縮後圖片的路徑
original_size_bytesnumber原始檔案大小(位元組)
compressed_size_bytesnumber壓縮後的檔案大小(位元組)
compression_rationumber壓縮比例

Example: Compress with quality setting

yaml
input_path: /path/to/image.jpg
quality: 75

Example: Compress to target size

yaml
input_path: /path/to/image.png
max_size_kb: 500

轉換圖片

image.convert

將圖片轉換為不同格式(PNG、JPEG、WEBP 等)

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-Path to the input image file
output_pathstringNo-Path where the processed image will be saved
formatselect (png, jpeg, webp, gif, bmp, tiff)YespngOutput image format
qualitynumberNo85Quality level (1-100, higher is better)
resizeobjectNo-Resize options:

Output:

FieldTypeDescription
pathstring轉換後圖片的路徑
sizenumber檔案大小(位元組)
formatstring輸出格式
dimensionsobject圖片尺寸

Example: Convert PNG to JPEG

yaml
input_path: /tmp/image.png
format: jpeg
quality: 90

裁剪圖片

image.crop

裁剪圖片到指定座標

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-輸入圖片的路徑
output_pathstringYes-輸出圖片的路徑
leftnumberYes-裁剪區域的左邊座標
topnumberYes-裁剪區域的上邊座標
rightnumberYes-裁剪區域的右邊座標
bottomnumberYes-裁剪區域的下邊座標

Output:

FieldTypeDescription
output_pathstring裁剪後圖片的路徑
widthinteger裁剪後圖片的寬度
heightinteger裁剪後圖片的高度
original_widthinteger原始圖片寬度
original_heightinteger原始圖片高度

Example: Crop center region

yaml
input_path: /path/to/image.png
output_path: /path/to/cropped.png
left: 100
top: 100
right: 500
bottom: 400

下載圖片

image.download

從網址下載圖片到本機檔案

Parameters:

NameTypeRequiredDefaultDescription
urlstringYes-URL of the image to download
output_pathstringNo-Path where the processed image will be saved
output_dirstringNo/tmpDirectory where output files will be saved
headersobjectNo{}HTTP request headers as key-value pairs
timeoutnumberNo30Maximum time to wait in seconds

Output:

FieldTypeDescription
pathstring下載圖片的本機路徑
sizenumber檔案大小(位元組)
content_typestring內容類型
filenamestring檔案名稱

Example: Download image from URL

yaml
url: https://example.com/photo.jpg
output_dir: /tmp/images

OCR 提取文字

image.ocr

使用 OCR 從圖片中提取文字

Parameters:

NameTypeRequiredDefaultDescription
image_pathstringYes-圖片檔案的路徑
languagestringNoengOCR 的語言代碼(例如:eng, chi_sim)
psmnumberNo3Tesseract 頁面分割模式
output_typeselect (text, data, boxes)NotextOCR 輸出的類型(文字或資料)

Output:

FieldTypeDescription
textstring從圖片中提取的文字
confidencenumberOCR 信心指數
languagestringOCR 使用的語言

Example: Extract text from image

yaml
image_path: /path/to/document.png
language: eng

產生 QR Code

image.qrcode_generate

從文字、網址或資料產生 QR Code

Parameters:

NameTypeRequiredDefaultDescription
datastringYes-Text, URL, or data to encode
output_pathstringNo-Path where the processed image will be saved
formatselect (png, svg)NopngOutput image format
sizenumberNo300Size in pixels
colorstringNo#000000Color of the QR code (hex or name)
backgroundstringNo#FFFFFFBackground color (hex or name)
error_correctionselect (L, M, Q, H)NoMError correction level
bordernumberNo4Border width in modules (quiet zone)
versionnumberNo-QR code version 1-40 (leave empty for auto-detect)
logo_pathstringNo-Path to logo image to embed in center

Output:

FieldTypeDescription
output_pathstring產生的 QR Code 圖片路徑
file_sizenumber輸出檔案大小(位元組)
dimensionsobjectQR Code 尺寸

Example: Generate URL QR code

yaml
data: https://flyto.dev
output_path: /tmp/flyto_qr.png

Example: Custom styled QR code

yaml
data: Hello World
color: #6366F1
size: 500
error_correction: H

Example: SVG QR code

yaml
data: https://flyto.dev
format: svg
border: 2

調整圖片大小

image.resize

使用各種演算法將圖片調整為指定尺寸

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-Path to the input image file
output_pathstringNo-Path where the processed image will be saved
widthnumberNo-Target width in pixels
heightnumberNo-Target height in pixels
scalenumberNo-Scale factor (e.g., 0.5 for half, 2.0 for double)
algorithmselect (lanczos, bicubic, bilinear, nearest)NolanczosResampling algorithm for resize
maintain_aspectbooleanNoTrueMaintain original aspect ratio

Output:

FieldTypeDescription
output_pathstring調整後圖片的路徑
original_sizeobject原始尺寸
new_sizeobject新尺寸

Example: Resize to specific dimensions

yaml
input_path: /path/to/image.png
width: 800
height: 600

Example: Scale by factor

yaml
input_path: /path/to/image.png
scale: 0.5

旋轉圖片

image.rotate

將圖片旋轉指定角度

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-輸入圖片的路徑
output_pathstringYes-輸出圖片的路徑
anglenumberYes-旋轉角度(度)
expandbooleanNoTrue展開輸出以容納整個旋轉後的圖片
fill_colorstringNo#000000旋轉後填補空白區域的顏色

Output:

FieldTypeDescription
output_pathstring旋轉後圖片的路徑
widthinteger旋轉後圖片的寬度
heightinteger旋轉後圖片的高度
anglenumber圖片旋轉的角度

Example: Rotate 90 degrees

yaml
input_path: /path/to/image.png
output_path: /path/to/rotated.png
angle: 90

新增浮水印

image.watermark

為圖片新增文字或圖片浮水印

Parameters:

NameTypeRequiredDefaultDescription
input_pathstringYes-輸入圖片的路徑
output_pathstringYes-輸出圖片的路徑
textstringNo-用作浮水印的文字
watermark_imagestringNo-用作浮水印的圖片檔案路徑
positionselect (center, top-left, top-right, bottom-left, bottom-right)Nobottom-right浮水印在圖片上的位置
opacitynumberNo0.5浮水印透明度(0.0 到 1.0)
font_sizenumberNo36文字浮水印的字型大小

Output:

FieldTypeDescription
output_pathstring浮水印圖片的路徑
watermark_typestring套用的浮水印類型(文字或圖片)

Example: Add text watermark

yaml
input_path: /path/to/image.png
output_path: /path/to/watermarked.png
text: © 2026 Company
position: bottom-right
opacity: 0.5

Released under the Apache 2.0 License.