Apr-22-2025, 12:39 PM
I have a single SVG file, called "container.svg" that contains a closed curve on a transparent background, something like this:
then I have a directory with other SVG files, each one contains some colored areas over a transparent background.
For the matter of this question we can just assume a simple rect or circle.
My goal is to load one image at time, move and scale it in order to "best fit" the inside of the container.svg shape.
That means the transparent areas can overlap, but the colored pixels should be kept inside the shape (with a specified gap) and each time a new image is loaded all of them should be moved and scaled (but not rotated) to fill all the available space.
This is similar to the "stock problem" you might face when you want to cut a piece of wood with several shapes and you want to use all the available surface minimizing the waste.
The output of my program should be the absolute position and size for each loaded image, so I can make an HTML page to represent the final result.
Is there any Python library I can use to do this? Or any idea to put me on the right way?
1 2 |
<?xml version = "1.0" encoding = "utf-8" ?> <svg baseProfile = "tiny" viewbox = "0 0 720 1080" height = "1080" version = "1.2" width = "720" xmlns = "http://www.w3.org/2000/svg" xmlns:ev = "http://www.w3.org/2001/xml-events" xmlns:xlink = "http://www.w3.org/1999/xlink" ><defs / ><ellipse cx = "360.0" cy = "540.0" fill = "none" rx = "324.0" ry = "486.0" stroke = "black" stroke - width = "2" / >< / svg> |
For the matter of this question we can just assume a simple rect or circle.
My goal is to load one image at time, move and scale it in order to "best fit" the inside of the container.svg shape.
That means the transparent areas can overlap, but the colored pixels should be kept inside the shape (with a specified gap) and each time a new image is loaded all of them should be moved and scaled (but not rotated) to fill all the available space.
This is similar to the "stock problem" you might face when you want to cut a piece of wood with several shapes and you want to use all the available surface minimizing the waste.
The output of my program should be the absolute position and size for each loaded image, so I can make an HTML page to represent the final result.
Is there any Python library I can use to do this? Or any idea to put me on the right way?