|
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# <http://www.gnu.org/licenses/>. |
31 |
# <http://www.gnu.org/licenses/>. |
32 |
|
32 |
|
33 |
import re, operator |
33 |
import re |
|
|
34 |
import operator |
34 |
import ipaddr |
35 |
import ipaddr |
35 |
import inspect |
36 |
import inspect |
36 |
import univention.debug |
37 |
import univention.debug |
|
46 |
import zlib |
47 |
import zlib |
47 |
import bz2 |
48 |
import bz2 |
48 |
import copy |
49 |
import copy |
49 |
import sys, os |
50 |
import sys |
|
|
51 |
import os |
50 |
import shlex |
52 |
import shlex |
|
|
53 |
import imghdr |
54 |
import PIL |
55 |
from io import BytesIO |
51 |
|
56 |
|
52 |
translation=univention.admin.localization.translation('univention/admin') |
57 |
translation=univention.admin.localization.translation('univention/admin') |
53 |
_=translation.translate |
58 |
_=translation.translate |
Lines 444-452
class jpegPhoto( Upload ):
|
Link Here
|
---|
|
444 |
@classmethod |
449 |
@classmethod |
445 |
def parse(self, text): |
450 |
def parse(self, text): |
446 |
try: |
451 |
try: |
|
|
452 |
raw = base64.b64decode(text) |
453 |
if imghdr.what(None, raw) == 'png': |
454 |
# convert from PNG to JPEG |
455 |
try: |
456 |
fp = BytesIO(raw) |
457 |
text = BytesIO() |
458 |
image = PIL.Image.open(fp) |
459 |
def _fileno(*a,**k): |
460 |
raise AttributeError() |
461 |
text.fileno = _fileno |
462 |
image.save(open('/tmp/test', 'w'), format='jpeg') |
463 |
image.save(text, format='jpeg') |
464 |
raw = text.getvalue() |
465 |
text = base64.b64encode(raw) |
466 |
except (KeyError, IOError): |
467 |
raise |
447 |
# imghdr.what(None, base64.b64dcode(text)) == 'jpeg' # See Bug #36304 |
468 |
# imghdr.what(None, base64.b64dcode(text)) == 'jpeg' # See Bug #36304 |
448 |
## this is what imghdr.py probably does in the future: |
469 |
## this is what imghdr.py probably does in the future: |
449 |
if base64.b64decode(text)[0:2] != b'\xff\xd8': |
470 |
if raw[0:2] != b'\xff\xd8': |
450 |
raise ValueError |
471 |
raise ValueError |
451 |
return text |
472 |
return text |
452 |
except (base64.binascii.Error, ValueError, TypeError): |
473 |
except (base64.binascii.Error, ValueError, TypeError): |