beeware / beeware/toga

Render Canvas to an arbitrarily-sized image

Open
#4,535 8 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

### What is the problem or limitation you are having?

I am building an app in which a preview of a document is displayed onscreen that is drawn using Canvas; however, I needed the ability to export that preview onto an arbitrarily-sized image.

### Describe the solution you'd like

A size parameter on as_image of Canvas that lets you export a scaled view of the Canvas.

This will be implemented in most backends by scaling the Canvas before rendering onto an image; reset_transform must be handled appropriately. Cocoa and iOS allows for setting a different logical size for an image than the physical size, which can be useful to implement this

### Describe alternatives you've considered

1. Status quo. One must manually resize the canvas, wait for layout, and then grab the image, and then reset image.
2. An canvas-like API on toga.Image that allows directly annotating an image.

### Additional context

A desktop implementation (with some additional fixes) without reset_transform support lives in johnzhou721/togax-frost, my personal component library. It has been used in johnzhou721/tiler successfully.

Contributor guide

Open the contributing guide

Research direction

Start by locating Canvas.as_image in each backend and review the desktop implementation in johnzhou721/togax-frost, including its reset_transform limitation. Compare the Cocoa and iOS logical-versus-physical image sizing behavior. Done means a size parameter exports the canvas at the requested dimensions without manual resize and layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.