Example #1
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
Example #2
0
 def XXXtest_word_to_images(self):
     blob = self.read_file("test.doc")
     image = converter.to_image("", blob, "application/msword", 0)
     eq_("image/jpeg", mime_sniffer.from_buffer(image))
Example #3
0
 def test_pdf_to_images(self):
     blob = self.read_file("onepage.pdf")
     image = converter.to_image("", blob, "application/pdf", 0)
     eq_("image/jpeg", mime_sniffer.from_buffer(image))