2017-07-01 28 views
0

私はこのコードを持って、それがorigionallyここから来ている:renaming files base on the file structure ここから機能するよう、私は保存サムネイルを追加しました:私は、ディレクトリ構造からすべてのファイルを選択しようとしているCreate thumbnail images for jpegs with python保存画像

ファイル構造に基づいて名前を変更します。私は 'in'を使用してフィルタを追加しましたが、サイズ変更のサムネイルを動作させることができません。

名前画像が定義されていません。

import os 
import shutil 
#testing 
import sys 
import image 


def image_thumb_filter(): 
size = 128, 128 
for path, dirs, files in os.walk(wd): 
    for file in files: 
    if file.endswith(".jpg"): 
     src = os.path.join(path, file) 
     #print(src) 
     dst = os.path.join(os.getcwd(), "Photo_selection") 
     if not os.path.exists(dst): #Checks 'Photos_mirror' folder exists 
otherwise creates 
     os.makedirs(dst) 
     new_name = src.replace(wd+'\\', '').replace('\\', '_') 
     new_dst = os.path.join(dst, new_name + "_thumb") 
     if not os.path.isfile(new_dst): 
     if "99\\526" in src: 
      try: 
       im = image.open(src) 
       im.thumbnail(size) 
       im.save(new_dst, "JPEG") 
      except IOError: 
       print ("cannot create thumbnail for", infile)    
    shutil.copy(src, dst) 
    old_dst = os.path.join(dst, file) 
       #Assuming your /dir/dir/... structure is inside of your working 
    directory (wd) 
    os.rename(old_dst, new_dst) 
    else: # it doesn't like this else statement 
    continue 
    image_thumb_filter() 

答えて

0

コード内の任意の場所にオブジェクト "イメージ"を定義していません。 Pythonや他の多くの言語では、大文字と小文字が区別されます。多分あなたは「イメージ?

+0

大文字と小文字は区別されない言語はどれですか? – Holloway

+0

コードを編集してもまだ動作しません....ピルインストールイメージ...ピロ、ジャンゴ、オレイルファイル、ピッツ、返信:トレースバック(最新のコールが最後): ファイル "" 、1行目 ModuleNotFoundError:モジュール 'image'がありません –

+0

@Holloway-SqL –