def explode_work_ticket(self, appstruct, checkout_id): """ If work_ticket in the filename, create an exploded mosaic thumbnail and add that to the database. """ lower_name = appstruct["file_upload"]["filename"].lower() if "work_ticket" not in lower_name \ or ".pdf" not in lower_name: return file_pointer = appstruct["file_upload"]["fp"] file_pointer.seek(0) thumg = ThumbnailGenerator(blob=file_pointer.read()) png_img = thumg.mosaic_thumbnail() thumbnail_name = "mosaic_work_ticket_thumbnail.png" new_file = File(filename=thumbnail_name, file_data=png_img) log.info("assign: %s to %s", new_file.filename, checkout_id) dbqry = DBSession.query(Checkout) checkout = dbqry.filter(Checkout.id == checkout_id).one() checkout.files.append(new_file) # Save the thumbnail to disk self.cache_blob(png_img, checkout_id, "mosaic_work_ticket_thumbnail.png")
def test_mosaic_thumbnail_from_blob(self): filename = "resources/known_unittest.pdf" pdf_file = open(filename) thumb = ThumbnailGenerator(blob=pdf_file.read()) png_img = thumb.mosaic_thumbnail() # Image has randomized components self.assertTrue(size_range(len(png_img), 21000, ok_range=2000))
def write_thumbnails(self, appstruct): """ Create the output filenames and generate the top and mosaic thumbnails and write them to disk. """ slugser = slugify(appstruct["serial"]) pdf_filename = "thumbnails/%s/uploaded.pdf" % slugser top_file = "thumbnails/%s/top.png" % slugser mos_file = "thumbnails/%s/mosaic.png" % slugser thumg = ThumbnailGenerator(pdf_filename) self.save_blob(thumg.top_thumbnail(), top_file) self.save_blob(thumg.mosaic_thumbnail(), mos_file)
def write_thumbnails(self, appstruct): """ Create the output filenames and generate the top and mosaic thumbnails and write them to disk. """ slugser = slugify(appstruct["serial"]) pdf_filename = "thumbnails/%s/uploaded.pdf" % slugser top_file = "thumbnails/%s/top.png" % slugser mos_file = "thumbnails/%s/mosaic.png" % slugser thumg = ThumbnailGenerator(pdf_filename) self.save_blob(thumg.top_thumbnail(), top_file) self.save_blob(thumg.mosaic_thumbnail(), mos_file)
def test_mosaic_thumbnail_from_pdf(self): filename = "resources/known_unittest.pdf" thumg = ThumbnailGenerator(filename) png_img = thumg.mosaic_thumbnail() # Image has randomized components self.assertTrue(size_range(len(png_img), 21000, ok_range=2000))
def test_top_page_thumbnail_from_pdf(self): filename = "resources/known_unittest.pdf" thumg = ThumbnailGenerator(filename) png_img = thumg.top_thumbnail() img_size = len(png_img) self.assertTrue(size_range(img_size, 105238, ok_range=5000))
def test_valid_pdf_does_not_throw_exception(self): filename = "resources/known_unittest.pdf" thumg = ThumbnailGenerator(filename) self.assertEqual(filename, thumg.filename)