How to use the imgkit.from_file function in imgkit

To help you get started, we’ve selected a few imgkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bendangnuksung / bota / bota / utility / general.py View on Github external
os.remove(fn)
	except Exception:
		pass
	text_file = open(fn, "a")

	# write the CSS
	text_file.write(css)
	# write the HTML-ized Pandas DataFrame
	text_file.write(data.to_html())
	text_file.close()

	# See IMGKit options for full configuration,
	# e.g. cropping of final image
	imgkitoptions = {"format": format}

	imgkit.from_file(fn, outputfile, options=imgkitoptions)
	os.remove(fn)

	img = Image.open(outputfile)
	width, height = img.size
	img = img.resize((int(width/1.2), int(height/1.2)), Image.ANTIALIAS)
	img.save(outputfile)

	return outputfile
github bendangnuksung / bota / bota / utility / general.py View on Github external
os.remove(fn)
	except Exception:
		pass
	text_file = open(fn, "a")

	# write the CSS
	text_file.write(css)
	# write the HTML-ized Pandas DataFrame
	text_file.write(data.to_html())
	text_file.close()

	# See IMGKit options for full configuration,
	# e.g. cropping of final image
	imgkitoptions = {"format": format}

	imgkit.from_file(fn, outputfile, options=imgkitoptions)
	os.remove(fn)

	img = Image.open(outputfile)
	width, height = img.size
	img = img.resize((int(width/1.2), int(height/1.2)), Image.ANTIALIAS)
	img.save(outputfile)

	return outputfile
github bendangnuksung / bota / utility.py View on Github external
os.remove(fn)
	except Exception:
		pass
	text_file = open(fn, "a")

	# write the CSS
	text_file.write(css)
	# write the HTML-ized Pandas DataFrame
	text_file.write(data.to_html())
	text_file.close()

	# See IMGKit options for full configuration,
	# e.g. cropping of final image
	imgkitoptions = {"format": format}

	imgkit.from_file(fn, outputfile, options=imgkitoptions)
	os.remove(fn)

	img = Image.open(outputfile)
	width, height = img.size
	img = img.resize((int(width/1.2), int(height/1.2)), Image.ANTIALIAS)
	img.save(outputfile)

	return outputfile
github andela / mrm_api / api / analytics / write_files.py View on Github external
}
            
            """
        fn = "file.html"
        try:
            os.remove(fn)
        except:  # noqa: E722
            None

        text_file = open(fn, "a")
        text_file.write(css)
        text_file.write('<br><br><h3>Most Booked Rooms</h3>' + df1.to_html(index=False) + '<br><br><h3>Least Booked Rooms</h3>' + df2.to_html(index=False) + '<br><br>')  # noqa: E501
        text_file.close()

        imgkitoptions = {"format": format}
        imgkit.from_file(fn, "templates/report_template.jpeg", options=imgkitoptions)  # noqa: E501
        os.remove(fn)
        im_gray = cv2.imread('templates/report_template.jpeg')
        img_str = cv2.imencode('.jpg', im_gray)[1].tostring()
        response = make_response(img_str)
        cd = 'attachment; filename=report.jpeg'
        response.headers['Content-Disposition'] = cd
        response.mimetype = 'image/jpeg'
        return response