いくつかのアイデアの心なので、いくつかの写真をつなぎ合わせする必要がある、アプリケーションの発見の多くをダウンロードした後APP直接操作結果を使用しての最初に考えたのは唯一のステッチの9枚の写真をサポートすることができます。そして、私のニーズを満たすことができない、いくつかの美し秀秀などを見つけ、私も動作するPSを使用するのではと思いますが、あなたがPSを使用している場合、それは時間がかかり、それを生きることになります。だから、小さな一角に建てられた枕フォトウォールの使用例を検索し、解決策を見つけるために引き続き、私は不確実性の突然多くのすべて、確かに見つける慎重に見て、これは私が欲しいものであると思いました。使用のPython +枕は、パズルがレコードを達成完成しました。
Pythonのインストールと枕
ボーエンは、参照の前にすることができますPythonとライブラリをインストールします。
プロセスやアイデア
需要:フォルダは、操作に名前または列方向の操作によってソートする進歩的な方法をネストされます。
プロセスが期待されています。
- 生成またはその後の画像の使用を必要とするかもしれ一時フォルダのキャッシュを作成します。
- 絵を読んだ後、それは特定の命名規則に従ったキャッシュフォルダに保存された前処理された画像になります
- 一時フォルダへのパスを切り替えます
- ターンで画像を開いて、画像合併
- 画像を保存するため、合併の完了後
- 一時フォルダを削除します
- 組み合わせた映像ショー
そのトリミングされた領域を確保するために、1:私はそれに続く必要パズルが正方形であるべき画像、私は写真画像をトリミングするために必要なすべてが1の割合になるので画像は、、、作物変換プレストレッチて回転されていてもよいです中央の画像は、長辺と短辺の必要性は、動作を決定しました。
写真をマージし、絵のコンバインド・レシオは、あまりにも変形することができない場合、可能な限り小さなとして空き領域が必要です。例えば、30枚の画像が配置されている5×6に分割することができ、31枚の写真は、4×8配列として配布されてもよいです。理想的な状態は、スクリプト自体は、どのように多くの写真や合理的な配分を認識している、この機能は一時的にDEMOを書かれていません、行と列は、現在、手動割り当てを要求します。
デモ
Pythonスクリプトで枕メソッド参照もDEMOプログラムを見ることができます。その中でも、
bol_auto_place
一時的に任意である、ように設定されているTrue
キャンバスのサイズを自動的のみピクチャの数の平方根によれば、合併後に割り当てられている示し、その後合併配置を設定する必要がある場合、手動設定、大きな正方形の画像にマージFalse
。
row
合併のための絵配電線の引数は、bol_auto_place == False
有効です。
col
合成画像は、列パラメータが分配されるbol_auto_place == False
有効。
nw
幅は、画像をキャッシュするように設定されているnh
画像の高さの設定をキャッシュします。ファイルの合計サイズは、自動的に画像キャッシュの配置や大きさによって設定されます。
DEMOスクリプトは、その詳細な説明を見ること、百度やGoogleを理解することはできませんいくつかの機能を持っていました。画像と一緒にスクリプトを使用する場合、現在の画像処理を表示する動作中に、実行をクリックし、画像処理は、合併の完了後に表示されます。で同じパスに保存された合併PNG形式の画像完了後splicing_picture.png
ファイル。デモプログラムのソースコードファイルといくつかの参照ダウンロードはこちらをクリックしてください。
#####################################################
# Notice ! #
# This script file should be placed in the same #
# folder as the image. #
#####################################################
import sys, os, shutil, math
from PIL import Image
#####################################################
# parameter setting #
#####################################################
bol_auto_place = False # auto place the image as a squared image, if 'True', ignore var 'row' and 'col' below
row = 4 # row number which means col number images per row
col = 8 # col number which means row number images per col
nw = 400 # sub image size, nw x nh
nh = 400
path = os.getcwd(); # acquire current folder path
if os.path.exists('tmp'): # ensure the 'tmp' folder is empty
shutil.rmtree('tmp')
os.makedirs('tmp')
file_ls = os.listdir() # list all files in this folder
i = 0 # a counter for images
for file in file_ls:
name, extension = os.path.splitext(file); # get file info[name, extension]
if (extension == '.png' or extension == '.jpg' or extension == '.jpeg') and name != 'splicing_picture': # select the image
i += 1 # image counter++
print('%s...%s%s' % (i, name, extension))
os.chdir(path) # ensure the image folder in every loop
im = Image.open(file) # open the image
w, h = im.size # get image info
#print('Original image size: %sx%s' % (w, h))
if nw == nh: # if image should be 1:1 size
if w >= h:
box = ((w - h) // 2, 0, (w + h) // 2, h)
else:
box = (0, (h - w) // 2, w, (h + w) // 2)
region = im.crop(box) # crop the image to 1:1 and keep center region
else:
region = im # do nothing
sname = '%s%s' % (str(i), '.png') # rename 'x.png', x is a number from 1 to N
os.chdir('tmp') # get into the folder 'tmp'
region.save(sname, 'png') # save the square image
os.chdir(path) # ensure the path
os.chdir('tmp')
if bol_auto_place: # auto place a big 1:1 square image
row = math.ceil(i ** 0.5)
col = math.ceil(i ** 0.5)
dest_im = Image.new('RGBA', (col * nw, row * nh), (255, 255, 255)) # the image size of splicing image, background color is white
for x in range(1, col + 1): # loop place the sub image
for y in range(1,row + 1):
try:
src_im = Image.open("%s.png" % str( x + ( y - 1 ) * col)) # open files in order
resize_im = src_im.resize((nw, nh), Image.ANTIALIAS) # resize again
dest_im.paste(resize_im, ((x-1) * nw, (y-1) * nh)) # paste to dest_im
except IOError:
pass
os.chdir(path) # ensure the path
shutil.rmtree('tmp') # delete the 'tmp'
dest_im.save('splicing_picture.png', 'png')
dest_im.show() # finish
レンダリングを実行します
30枚の写真は実施例4×8に従って配置され、スプライトの効果は、図において以下に示されています。そのような個人のために、まだ結果に非常に満足している、それは5×6ウェイの配置に調整することができ、簡単に変更するrow
とcol
、パラメータの設定ができ後に再実行します。