Split-Image เป็นแพ็คเกจ Python ที่คุณสามารถใช้จากบรรทัดคำสั่งเพื่อแยกภาพออกเป็นกระเบื้อง
pip install split-image
จากบรรทัดคำสั่ง:
split-image [-h] [-s] image_path rows cols
เป็นการนำเข้าโมดูลปกติ:
from split_image import split_image
split_image ( image_path , rows , cols , should_square , should_cleanup , [ output_dir ])
# e.g. split_image("bridge.jpg", 2, 2, True, False)
split-image cat.png 2 2
สิ่งนี้แยกภาพ cat.png
ใน 4 กระเบื้อง ( 2
แถวและ 2
คอลัมน์)
split-image bridge.png 3 4 -s
สิ่งนี้จะแยกภาพ bridge.png
ใน 12 กระเบื้อง ( 3
แถวและ 4
คอลัมน์) อาร์กิวเมนต์ -square
ปรับขนาดภาพเป็นสี่เหลี่ยมจัตุรัสก่อนที่จะแยกออก สีพื้นหลังที่ใช้ในการเติมสี่เหลี่ยมจะถูกกำหนดจากภาพโดยอัตโนมัติ
split-image cat.jpg 2 2 -r
จะพยายามผสานกระเบื้องรูปภาพที่มีชื่อคล้ายกันกับภาพเดียว ดังนั้นหากคุณมีภาพเหล่านี้ในไดเรกทอรีปัจจุบัน:
cat_0.jpg
cat_1.jpg
cat_2.jpg
cat_3.jpg
พวกเขาจะถูกรวมตามชื่อไฟล์ของพวกเขา:
split-image image_dir 4 2
จะแยกภาพทั้งหมดที่อยู่ในโฟลเดอร์ image_dir
split-image test.jpg 4 2 --cleanup
จะลบภาพต้นฉบับหลังจากกระบวนการ
split-image test.jpg 4 2 --load-large-images
เมื่อทำงานกับภาพขนาดใหญ่ (มากกว่า 178,956,970 พิกเซล) คุณอาจได้รับข้อผิดพลาด ผ่านธงนี้เพื่อแทนที่สิ่งนี้
split-image test.jpg 2 2 --output-dir <dir-name>
ตั้งค่าไดเรกทอรีเอาต์พุตสำหรับกระเบื้องรูปภาพ (เช่น 'outp/images') ค่าเริ่มต้นไปยังไดเรกทอรีการทำงานปัจจุบัน
split-image test.jpg 3 4 --quiet
จะระงับข้อความบันทึกทั้งหมด (ยกเว้นข้อผิดพลาดและคำเตือน) เมื่อทำงาน
positional arguments:
image_path The path to the image or directory with images to split.
rows How many rows to split the image into (horizontal split).
cols How many columns to split the image into (vertical split).
optional arguments:
-h, --help Show this help message and exit
-s, --square If the image should be resized into a square before splitting.
-r, --reverse Reverse the splitting process, i.e. merge multiple tiles of an image into one.
--cleanup After splitting or merging, delete the original image/images.
--load-large-images Pass this flag for use with really large images.
--output-dir <dir-name> Set the output directory for image tiles (e.g. 'outp/images').
--quiet Run without printing any messages.
ภาพถ่ายแมวโดย Manja Vitolic บน Unsplash
Bridge Photo โดย Lance Asper บน Unsplash