Skip to content

Conversation

@dom96
Copy link
Contributor

@dom96 dom96 commented Nov 18, 2025

Deployed URL: https://python-image-gen.runtime-playground.workers.dev

Screenshot 2025-11-18 at 17 42 25

Mostly generated using GenAI.

CC @ryanking13

Comment on lines +333 to +342
image_bytes = buffer.getvalue()

# Create and return response with appropriate headers
return Response(
to_js(image_bytes).buffer,
headers={
"Content-Type": content_type,
"Cache-Control": "public, max-age=3600",
},
)
Copy link
Contributor

@hoodmane hoodmane Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One copy instead of two:

Suggested change
image_bytes = buffer.getvalue()
# Create and return response with appropriate headers
return Response(
to_js(image_bytes).buffer,
headers={
"Content-Type": content_type,
"Cache-Control": "public, max-age=3600",
},
)
image_bytes = create_proxy(buffer.getvalue())
jsbuffer = image_bytes.getBuffer()
try:
# Create and return response with appropriate headers
return Response(
jsbuffer.data,
headers={
"Content-Type": content_type,
"Cache-Control": "public, max-age=3600",
},
)
finally:
image_bytes.destroy()
jsbuffer.release()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I tried this and it doesn't work: I get a corrupted image. This is what it's returning:

Screenshot 2025-11-20 at 12 11 24

Return an HTML page showing available endpoints and examples.
"""
html = """
<!DOCTYPE html>
Copy link
Contributor

@hoodmane hoodmane Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we move this into it's own .html file and do

  endpoints = Path(__file__).parent / "endpoints.html"
  return Response(endpoints.read_text(), headers={"Content-Type": "text/html"})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is a great example too that we should put in our docs somewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants