Пример #1
0
                c1 = c2
                c2 = cad.read(1)
                if c2 == '':
                    # end of file, raises an exception so that the thumbnailer fails
                    raise Exception()
            cad.seek(-2, 1)

        done = False
        while not done:
            seek()
            try:
                im = Image.open(SeekedFile(cad))
            except IOError:
                # not a JPEG, goes forward and looks up for another
                # magic number
                cad.seek(3, 1)
            else:
                # looks good, save the image
                im.thumbnail(ThumbnailersManager.THUMBNAIL_SIZE,
                             Image.ANTIALIAS)
                im.save(output_path)
                done = True
    return False


CATIA_FILES = ("catpart", "catproduct", "catdrawing")
PRO_ENGINEER_FILES = ("asm", "prt")
FILES = CATIA_FILES + PRO_ENGINEER_FILES
for ext in FILES:
    ThumbnailersManager.register("." + ext, jfif_thumbnailer)
Пример #2
0
import Image

from base import ThumbnailersManager


def pil_thumbnailer(input_path, original_filename, output_path):
    """
    Thumbnailer that uses PIL to generate a thumbnail from an
    image.
    """
    im = Image.open(input_path)
    im.thumbnail(ThumbnailersManager.THUMBNAIL_SIZE, Image.ANTIALIAS)
    im.save(output_path)
    return False


Image.init()
for ext, name in Image.EXTENSION.iteritems():
    if name in Image.OPEN:
        ThumbnailersManager.register(ext, pil_thumbnailer)
Пример #3
0
    ".uyvy",
    ".vda",
    ".vicar",
    ".vid",
    ".viff",
    ".vst",
    ".wbmp",
    ".wmf",
    ".wmv",
    ".wmz",
    ".wpg",
    ".x",
    ".x3f",
    ".xbm",
    ".xc",
    ".xcf",
    ".xpm",
    ".xps",
    ".xv",
    ".xwd",
    ".y",
    ".ycbcr",
    ".ycbcra",
    ".yuv",
)

# some formats may not be available, but it is simpler/faster to let
# imagemagick fail than checking available format.
for ext in FORMATS:
    ThumbnailersManager.register(ext, magick_thumbnailer)
Пример #4
0
#: Supported formats (if all ImageMagick decoders are installed)
FORMATS = (".3fr", ".a", ".ai", ".art", ".arw", ".avi", ".avs", ".b", ".bgr",
           ".bgra", ".bmp", ".brg", ".c", ".cal", ".cals", ".caption", ".cin",
           ".cmyk", ".cmyka", ".cr2", ".crw", ".cur", ".cut", ".dcm", ".dcr",
           ".dcx", ".dds", ".dfont", ".djvu", ".dng", ".dot", ".dpx", ".epdf",
           ".epi", ".eps", ".epsf", ".epsi", ".ept", ".ept2", ".ept3", ".erf",
           ".exr", ".fax", ".fits", ".fractal", ".fts", ".g", ".g3", ".gbr",
           ".gif", ".gif87", ".gradient", ".gray", ".grb", ".group4", ".hald",
           ".hrz", ".icb", ".ico", ".icon", ".inline", ".ipl", ".j2c", ".jng",
           ".jp2", ".jpc", ".jpeg", ".jpg", ".jpx", ".k", ".k25", ".kdc",
           ".label", ".m", ".m2v", ".m4v", ".map", ".mat", ".miff", ".mng",
           ".mono", ".mov", ".mp4", ".mpc", ".mpeg", ".mpg", ".mrw", ".msl",
           ".msvg", ".mtv", ".mvg", ".nef", ".null", ".o", ".orf", ".otb",
           ".otf", ".pal", ".palm", ".pam", ".pattern", ".pbm", ".pcd",
           ".pcds", ".pcl", ".pct", ".pcx", ".pdb", ".pdf", ".pdfa", ".pef",
           ".pes", ".pfa", ".pfb", ".pfm", ".pgm", ".pgx", ".picon", ".pict",
           ".pix", ".pjpeg", ".plasma", ".png", ".png24", ".png32", ".png8",
           ".pnm", ".ppm", ".ps", ".psb", ".psd", ".ptif", ".pwp", ".r",
           ".raf", ".ras", ".rbg", ".rgb", ".rgba", ".rgbo", ".rla", ".rle",
           ".scr", ".sct", ".sfw", ".sgi", ".sr2", ".srf", ".stegano", ".sun",
           ".svg", ".svgz", ".text", ".tga", ".tiff", ".tile", ".tim", ".ttc",
           ".ttf", ".txt", ".uyvy", ".vda", ".vicar", ".vid", ".viff", ".vst",
           ".wbmp", ".wmf", ".wmv", ".wmz", ".wpg", ".x", ".x3f", ".xbm",
           ".xc", ".xcf", ".xpm", ".xps", ".xv", ".xwd", ".y", ".ycbcr",
           ".ycbcra", ".yuv")

# some formats may not be available, but it is simpler/faster to let
# imagemagick fail than checking available format.
for ext in FORMATS:
    ThumbnailersManager.register(ext, magick_thumbnailer)
Пример #5
0
            " Seek to the possible start of a JPEG file"
            c1, c2 = cad.read(1), cad.read(2)
            while c1 + c2 != '\xff\xd8':
                c1 = c2
                c2 = cad.read(1)
                if c2 == '':
                    # end of file, raises an exception so that the thumbnailer fails
                    raise Exception()
            cad.seek(-2, 1)
        done = False
        while not done:
            seek()
            try: 
                im = Image.open(SeekedFile(cad))
            except IOError:
                # not a JPEG, goes forward and looks up for another
                # magic number
                cad.seek(3, 1)
            else:
                # looks good, save the image
                im.thumbnail(ThumbnailersManager.THUMBNAIL_SIZE, Image.ANTIALIAS)
                im.save(output_path)
                done = True
    return False

CATIA_FILES = ("catpart", "catproduct", "catdrawing")
PRO_ENGINEER_FILES = ("asm", "prt")
FILES = CATIA_FILES + PRO_ENGINEER_FILES
for ext in FILES:
    ThumbnailersManager.register("." + ext, jfif_thumbnailer)
Пример #6
0
                data = cad.read(1024)
                # end of file, raises an exception so that the thumbnailer fails
                if not data:
                    raise Exception()
                pos = data.find(PNG_MAGIC_NUMBER)
            cad.seek(t + pos)

        done = False
        while not done:
            seek()
            try:
                im = Image.open(SeekedFile(cad))
            except IOError:
                # not a PNG, goes forward and looks up for another
                # magic number
                cad.seek(5, 1)
            else:
                # looks good, save the image
                im.thumbnail(ThumbnailersManager.THUMBNAIL_SIZE,
                             Image.ANTIALIAS)
                im.save(output_path)
                done = True
    return False


FILES = (
    "skp",  # google sketch up
)
for ext in FILES:
    ThumbnailersManager.register("." + ext, png_thumbnailer)
Пример #7
0
            pos = data.find(PNG_MAGIC_NUMBER)
            while pos == -1:
                data = cad.read(1024)
                # end of file, raises an exception so that the thumbnailer fails
                if not data:
                    raise Exception()
                pos = data.find(PNG_MAGIC_NUMBER)
            cad.seek(t + pos)

        done = False
        while not done:
            seek()
            try: 
                im = Image.open(SeekedFile(cad))
            except IOError:
                # not a PNG, goes forward and looks up for another
                # magic number
                cad.seek(5, 1)
            else:
                # looks good, save the image
                im.thumbnail(ThumbnailersManager.THUMBNAIL_SIZE, Image.ANTIALIAS)
                im.save(output_path)
                done = True
    return False

FILES = ("skp", # google sketch up
    )
for ext in FILES:
    ThumbnailersManager.register("." + ext, png_thumbnailer)

Пример #8
0
"""

import re
import subprocess

from base import ThumbnailersManager

def sw_thumbnailer(input_path, original_filename, output_path):
    """
    Thumbnailer that extracts a thumlbnail of a SolidWorks file.
    """
    out = subprocess.Popen(["gsf", "list", input_path], stdout=subprocess.PIPE).communicate()[0]
    previews = re.findall("[\w/-]*PreviewPNG", out)
    if not previews:
        raise ValueError("No preview found")
    done = False
    for preview in previews:
        with open(output_path, "wb") as png_file:
            args = ["gsf", "cat", input_path, preview]
            call = subprocess.call(args, stdout=png_file)
            done = call == 0
        if done:
            break
    return True

#: Supported formats
FORMATS = (".sldprt", ".sldasm", ".slddrw", ".slddrt")

for ext in FORMATS:
    ThumbnailersManager.register(ext, sw_thumbnailer)