Exemplo n.º 1
0
  def convert(self, blob, size=500):
    """Size is the maximum horizontal size."""

    in_fn = make_temp_file(blob)
    out_fn = mktemp(dir=TMP_DIR)
    l = []

    try:
      subprocess.check_call(['pdftoppm', '-jpeg', in_fn, out_fn])

      l = glob.glob("%s-*.jpg" % out_fn)
      l.sort()
      converted_images = []
      for fn in l:
        converted = resize(open(fn).read(), size)
        converted_images.append(converted)

      return converted_images
    except Exception, e:
      raise ConversionError(e)
Exemplo n.º 2
0
def preview(file_id):
  """Returns a preview (image) for the file given by its id."""

  f = get_file(file_id)
  size = int(request.args.get("size", 0))

  # Just in case
  if size > 1000:
    size = 1000

  if f.mime_type.startswith("image/"):
    image = f.data
    if size:
      image = resize(image, size)
  else:
    page = int(request.args.get("page", 0))
    image = converter.to_image(f.digest, f.data, f.mime_type, page, size)

  response = make_response(image)
  response.headers['content-type'] = "image/jpeg"

  return response