2014-10-13 2 views
0

링크에서 이미지를 가져올 스크립트를 작성 중입니다. 그런 다음 이미지는 PIL 모듈을 사용하여 크기가 조정되고 pyimgur을 사용하여 Imgur에 업로드됩니다. 디스크에 이미지를 저장하고 대신 이미지를 메모리에 저장 한 다음 메모리에서 Imgur로 업로드하려고합니다. 스크립트에게 :이 스크립트를 실행하면크기 조정 후 이미지를 Imgur에 업로드 PIL

from pyimgur import Imgur 
import cStringIO 
import requests 
from PIL import Image 

LINK = "http://pngimg.com/upload/cat_PNG106.png" 
CLIENT_ID = '29619ae5d125ae6' 
im = Imgur(CLIENT_ID) 

def _upload_image(img, title): 
    uploaded_image = im.upload_image(img, title=title) 
    return uploaded_image.link 

def _resize_image(width, height, link): 
    #Retrieve our source image from a URL 
    fp = requests.get(link) 
    #Load the URL data into an image 
    img = cStringIO.StringIO(fp.content) 
    im = Image.open(img) 
    #Resize the image 
    im2 = im.resize((width, height), Image.NEAREST) 
    #saving the image into a cStringIO object to avoid writing to disk 
    out_im2 = cStringIO.StringIO() 
    im2.save(out_im2, 'png') 
    return out_im2.getvalue() 

나는이 오류가 발생합니다 : TypeError: file() argument 1 must be encoded string without NULL bytes, not str 누구나 마음에 솔루션을?

+0

GData API를 사용하여 Google App Engine에서 Picasa로 사진을 업로드하려고 할 때 [TypeError]가 중복 될 수 있습니다. (http://stackoverflow.com/questions/1715574/typeerror-when-trying-to-upload-pictures-from -google-app-engine-to-picasa-with-t) –

답변

0

this과 같은 문제인 것처럼 보이며 해결 방법은 StringIO를 사용하는 것입니다.

이러한 문제를 검색 할 때 일반적인 팁은 오류 메시지/문자열의 일반적인 부분을 사용하여 검색하는 것입니다.

+0

여전히 같은 오류가 발생합니다! – jjjj

+0

im2.save (out_im2, format = "PNG")는 어떻습니까? http://stackoverflow.com/questions/646286/python-pil-how-to-write-png-image-to-string을 참조하고 있습니다. – Hemanth