Browse Source

update

pull/6/head
Mathias Markl 6 years ago
parent
commit
79577131cd
  1. 3
      muk_thumbnails/__manifest__.py
  2. 32
      muk_thumbnails/service/thumbnail.py

3
muk_thumbnails/__manifest__.py

@ -20,11 +20,10 @@
{ {
"name": 'MuK Thumbnails', "name": 'MuK Thumbnails',
"summary": """File Thumbnails""", "summary": """File Thumbnails""",
"version": '11.0.1.0.0',
"version": '11.0.1.0.1',
"category": 'Document Management', "category": 'Document Management',
"license": "AGPL-3", "license": "AGPL-3",
"website": "http://www.mukit.at", "website": "http://www.mukit.at",
"live_test_url": "https://demo.mukit.at/web/login",
"author": "MuK IT", "author": "MuK IT",
"contributors": [ "contributors": [
"Mathias Markl <mathias.markl@mukit.at>", "Mathias Markl <mathias.markl@mukit.at>",

32
muk_thumbnails/service/thumbnail.py

@ -39,8 +39,10 @@ _logger = logging.getLogger(__name__)
try: try:
from wand.image import Image from wand.image import Image
from wand.color import Color
except ImportError: except ImportError:
Image = False Image = False
Color = False
_logger.warn('Cannot `import wand`.') _logger.warn('Cannot `import wand`.')
try: try:
@ -68,13 +70,13 @@ PDF_IMPORTS = [
] ]
WAND_IMPORTS = [ WAND_IMPORTS = [
"aai", "art", "arw", "avi", "avs", "bpg", "brf", "cals", "cgm", "cin", "cip", "cmyk", "cmyka",
"aai", "art", "arw", "avi", "avs", "bpg", "brf", "cals", "cgm", "cin", "cip", "cmyk", "cmyka", "svg",
"cr2", "crw", "cur", "cut", "dcm", "dcr", "dcx", "dds", "dib", "djvu", "dng", "dot", "dpx", "tim", "cr2", "crw", "cur", "cut", "dcm", "dcr", "dcx", "dds", "dib", "djvu", "dng", "dot", "dpx", "tim",
"emf", "epdf", "epi", "eps", "eps2", "eps3", "epsf", "epsi", "ept", "exr", "fax", "fig", "fits", "emf", "epdf", "epi", "eps", "eps2", "eps3", "epsf", "epsi", "ept", "exr", "fax", "fig", "fits",
"fpx", "gplt", "gray", "graya", "hdr", "hdr", "heic", "hpgl", "hrz", "html", "ico", "info", "ttf", "fpx", "gplt", "gray", "graya", "hdr", "hdr", "heic", "hpgl", "hrz", "html", "ico", "info", "ttf",
"inline", "isobrl", "isobrl6", "jbig", "jng", "jp2", "jpt", "j2c", "j2k", "jxr", "json", "man", "bmp", "inline", "isobrl", "isobrl6", "jbig", "jng", "jp2", "jpt", "j2c", "j2k", "jxr", "json", "man", "bmp",
"mat", "miff", "mono", "mng", "m2v", "mpeg", "mpc", "mpr", "mrw", "msl", "mtv", "mvg", "nef", "yuv", "mat", "miff", "mono", "mng", "m2v", "mpeg", "mpc", "mpr", "mrw", "msl", "mtv", "mvg", "nef", "yuv",
"orf", "otb", "p7", "palm", "pam", "clipboard", "pbm", "pcd", "pcds", "pcl", "pcx", "pdb", "pdf", "jpe",
"orf", "otb", "p7", "palm", "pam", "clipboard", "pbm", "pcd", "pcds", "pcl", "pcx", "pdb", "jpe",
"pef", "pes", "pfa", "pfb", "pfm", "pgm", "picon", "pict", "pix", "png8", "png00", "png24", "tiff", "pef", "pes", "pfa", "pfb", "pfm", "pgm", "picon", "pict", "pix", "png8", "png00", "png24", "tiff",
"png32", "png48", "png64", "pnm", "ppm", "ps", "ps2", "ps3", "psb", "psd", "ptif", "pwp", "rad", "bmp2", "png32", "png48", "png64", "pnm", "ppm", "ps", "ps2", "ps3", "psb", "psd", "ptif", "pwp", "rad", "bmp2",
"raf", "rgb", "rgba", "rgf", "rla", "rle", "sct", "sfw", "sgi", "shtml", "sid", " mrsid", "jpeg", "bmp3", "raf", "rgb", "rgba", "rgf", "rla", "rle", "sct", "sfw", "sgi", "shtml", "sid", " mrsid", "jpeg", "bmp3",
@ -120,20 +122,26 @@ def create_thumbnail(binary, mimetype=None, filename=None, export="binary", form
image_extension = extension image_extension = extension
if extension in WAND_IMPORTS: if extension in WAND_IMPORTS:
image_data = binary image_data = binary
elif not image_data and extension in PDF_IMPORTS:
reader = PyPDF2.PdfFileReader(io.BytesIO(binary))
elif not image_data and (extension in PDF_IMPORTS or extension in unoconv.IMPORTS):
pdf_data = binary if extension in PDF_IMPORTS else None
if not pdf_data:
image_extension = "pdf"
pdf_data = unoconv.convert_binary(binary, mimetype, filename)
reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_data))
writer = PyPDF2.PdfFileWriter() writer = PyPDF2.PdfFileWriter()
if reader.getNumPages() >= page:
writer.addPage(reader.getPage(page)) writer.addPage(reader.getPage(page))
thumbnail_bytes = io.BytesIO()
thumbnail_pdf.write(thumbnail_bytes)
image_data = thumbnail_bytes.seek(0)
image_extension = "pdf"
elif not image_data and extension in unoconv.IMPORTS:
image_data = unoconv.convert_binary(binary, mimetype, filename)
image_extension = "pdf"
else:
writer.addPage(reader.getPage(0))
pdf_bytes = io.BytesIO()
writer.write(pdf_bytes)
image_data = pdf_bytes.getvalue()
if image_data: if image_data:
with Image(blob=image_data, format=image_extension) as thumbnail: with Image(blob=image_data, format=image_extension) as thumbnail:
thumbnail.format = format thumbnail.format = format
if image_extension == "pdf":
thumbnail.background_color = Color('white')
thumbnail.alpha_channel = 'remove'
if image_resize: if image_resize:
thumbnail.transform(resize=image_resize) thumbnail.transform(resize=image_resize)
if image_crop: if image_crop:
@ -171,6 +179,8 @@ def create_thumbnail(binary, mimetype=None, filename=None, export="binary", form
writer.append_data(image) writer.append_data(image)
elif clip.duration > int(frame): elif clip.duration > int(frame):
clip.save_frame(tmp_opath, t=int(frame)) clip.save_frame(tmp_opath, t=int(frame))
else:
clip.save_frame(tmp_opath, t=int(0))
if os.path.isfile(tmp_opath): if os.path.isfile(tmp_opath):
with open(tmp_opath, 'rb') as file: with open(tmp_opath, 'rb') as file:
if export == 'file': if export == 'file':

Loading…
Cancel
Save