Commit 2260ad0c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

if PIL is missing, use ImageMagick's identify command.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38531 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2396541d
...@@ -70,7 +70,6 @@ import os ...@@ -70,7 +70,6 @@ import os
from threading import Thread from threading import Thread
import httplib import httplib
import urllib import urllib
from PIL import Image
from AccessControl import Unauthorized from AccessControl import Unauthorized
QUIET = 0 QUIET = 0
...@@ -1967,8 +1966,16 @@ return 1 ...@@ -1967,8 +1966,16 @@ return 1
f.close() f.close()
infile.close() infile.close()
file_size = len(image_data) file_size = len(image_data)
try:
from PIL import Image
image = Image.open(filename) image = Image.open(filename)
image_size = image.size image_size = image.size
except ImportError:
from subprocess import Popen, PIPE
identify_output = Popen(['identify', filename],
stdout=PIPE).communicate()[0]
image_size = tuple(map(lambda x:int(x),
identify_output.split()[2].split('x')))
os.remove(filename) os.remove(filename)
return image_size, file_size return image_size, file_size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment