Kozea / Kozea/CairoSVG

Support for skewed output aspect ratio

Open
#272 0 comments 1 reaction 0 assignees View on GitHub
feature
Dominant language
Python
Stars
951
Forks
166
PR merge metrics
No merged PRs in 30d

Description

Hello,
I kindly request a feature to allow the image to be skewed according to the output width and height.
Currently if the aspect ratio of the output_width and output_height does not match the aspect ratio of the svg-viewbox, it will make an output image, that has the correct size, however, the image is scaled down, so it will fit completely on the canvas while maintaining its original aspect ratio.

I would like to skew the image in the output, for example: skew a circle to an oval.

For example: Look at the following svg.
``
`
`
No matter how I play around with parent_width, parent_height, output_width, output_height, the circle always appears round in the final image.

I think I traced it down to the line:
surface.py, line 245 `scale_x, scale_y, translate_x, translate_y = preserve_ratio(self, tree, width, height)`
where the scaling happens.

For the user, it would be easiest if he could supply an additional parameter 'keepAspectRatio=False', like this:
`cairosvg.svg2png(bytestring=input, write_to=output,`
`parent_width = 50, parent_height = 50,
output_width = 100, output_height = 50,`
`keepAspectRatio=False)`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at surface.py line 245 and inspect preserve_ratio, which currently determines the scaling and translation. Trace how parent_width, parent_height, output_width, and output_height reach that code, then verify the requested option would render the example circle as an oval at 100x50 without preserving the source aspect ratio.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.