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
同様に指名された画像タイルを1つの画像にマージしようとします。したがって、現在のディレクトリにこれらの画像がある場合:
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.
猫の写真:マンジャのin gitolic by Unsplash
ランスアスパーによる橋の写真