Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions datasette_render_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from markupsafe import Markup

DEFAULT_SIZE_LIMIT = 100 * 1024
DEFAULT_WIDTH = 300
DEFAULT_HEIGHT =300


@hookimpl
Expand All @@ -12,6 +14,8 @@ def render_cell(value, datasette):
if datasette:
plugin_config = datasette.plugin_config("datasette-render-images") or {}
size_limit = plugin_config.get("size_limit") or DEFAULT_SIZE_LIMIT
width = plugin_config.get("width") or DEFAULT_WIDTH
height = plugin_config.get("height") or DEFAULT_HEIGHT
# Only act on byte columns
if not isinstance(value, bytes):
return None
Expand All @@ -24,7 +28,7 @@ def render_cell(value, datasette):
return None
# Render as a data-uri
return Markup(
'<img src="data:image/{};base64,{}" alt="">'.format(
image_type, base64.b64encode(value).decode("utf8")
'<img src="data:image/{};base64,{}" alt="" width={} height={}>'.format(
image_type, base64.b64encode(value).decode("utf8"), width, height
)
)