2016-08-01 2 views
0

나는 다음과 같이 그레이 스케일로 변환 된 이미지를 업로드하려고 :업로드 그레이 스케일 이미지 파이썬

blob_path = os.path.join(os.path.split(__file__)[0], 'static/img/blob-masks/1.png') 
blob = Image.open(blob_path).convert('L') 
buffer = StringIO() 
blob.save(buffer) 
upload_image(buffer.getvalue(),"foo.png") 

을하지만 그냥 검은 색 사각형을 업로드 할 것으로 보인다. 내가 명령 줄 파이썬에 도착했고 실행하면

:

col = Image.open("/static/img/blob-masks/5.png") 
col.convert('L') 
col.save("result_bw.png") 

result_bw.png은 완벽합니다. 무슨 일 이니?

답변

0

그레이 스케일 이미지를 변환 한 후 업로드 할 수없는 이유가 있습니까? 마찬가지로 :

image = Image.open('static/img/blob-masks/1.png') 
image.convert('L') 
image.save("temp/bw.png") 
upload_image("temp/bw.png") 
# maybe delete the temporary file when you're done 
import os 
os.remove("temp/bw.png") 

나는 당신의 upload_image() 함수가 어떻게 작동하는지 모르겠지만, 내가 어떤 조작을 할 경우 내가 장고를 사용하여 업로드 할 때 나는 다음 임시 파일을 다시 가져 오기를 작성합니다. 이미지를 조작하지 않으면 직접 업로드 할 수 있습니다.

관련 문제