2017-02-07 10 views
0

私はコンピュータコーディングに新人です。我々はPYTHONを行うためにCanopyと連携し、画像の変更を行っています。私は 'モジュール'オブジェクトに属性 '描画'エラーがなく、修正方法がわからない。私は次のようにインポートしている:'module'オブジェクトには属性 'draw'の意味がありません。どうすれば修正できますか?

import PIL 
import os.path 
import PIL.ImageDraw    
import PIL 
from PIL import ImageFont 
from PIL import Image 
from PIL import ImageDraw 

そして、私が実行しようとしているコードです:それはあなたが(描画されて探している方法のように見えるのドキュメント)、描画しないから

def round_corners_of_all_images(directory=None): 
    """ Saves a modfied version of each image in directory. 

    Uses current directory if no directory is specified. 
    Places images in subdirectory 'modified', creating it if it does not exist. 
    New image files are of type PNG and have transparent rounded corners. 
    """ 

    if directory == None: 
     directory = os.getcwd() # Use working directory if unspecified 

    # Create a new directory 'modified' 
    new_directory = os.path.join(directory, 'modified') 
    try: 
     os.mkdir(new_directory) 
    except OSError: 
     pass # if the directory already exists, proceed 

    #load all the images 
    image_list, file_list = get_images(directory) 

    #go through the images and save modified versions 
    for n in range(len(image_list)): 
     # Parse the filename 
     filename, filetype = file_list[n].split('.') 

     # drawing the text on the picture 
     draw = ImageDraw.Draw(image_list[n]) 
     font = ImageFont.truetype("Infinite_Stroke",size=24,index=0,encoding="unic") 
     draw.text((10, 25),(0,0,255),"SAMSUNG", font=font) 

     # Round the corners with radius = 30% of short side 
     new_image = round_corners(image_list[n],.30) 
     #save the altered image, suing PNG to retain transparency 
     new_image_filename = os.path.join(new_directory, filename + '.jpg') 
     new_image.save(new_image_filename)  
+2

私はちょうど間違った大文字を使用していると信じています: 'draw = ImageDraw.draw(image_list [n])' - > 'draw = ImageDraw.Draw(image_list [n])' –

+0

私はそれを試みました。 。 – evaaaannnnnnnn

+2

あなたのエラーを_describe_しないでください - 完全なトレースバックをコピーして貼り付けてください。 – DSM

答えて

1

( )

http://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html

この

draw = ImageDraw.Draw(image_list[n]) 
をお試しください
+0

私はそれを試みました、そして、私はまだ同じメッセージを受け取ります。 – evaaaannnnnnnn

+0

投稿を編集して新しいコードを表示できますか?私はあなたがまだ同じエラーメッセージを得るのは非常に奇妙だと思っています。 –

+0

新しいコードを表示するために質問を編集しました。 – evaaaannnnnnnn

関連する問題