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 optional parameters to limit the maximum dimensions ---max-width, --max-height #647

Open
totoestcontent opened this issue Jul 18, 2023 · 9 comments

Comments

@totoestcontent
Copy link

Some svgs have a huge viewbox and I would need to limit the size of the png produced.
The current settings (-w and -h) allow this if the image is larger than the given values.
If the image is smaller then it will be enlarged.
The idea is therefore not to exceed a given dimension (optional).

I made the changes and created a git patch.

Be indulgent, it's the first time I do Rust ;-)
So you can do much better, but if it can make your job easier, I'd be happy ;-)

add_max_width_height.patch

@RazrFalcon
Copy link
Owner

What behavior do you expect? I would assume that images larger than required should simply be rejected, while your patch simply downscales them.

@totoestcontent
Copy link
Author

I need to preview all svg images with a maximum dimension of 200x200.
If the svgs are smaller than 200x200 then the previews must be the size of the svg.
If the svgs are larger, then the preview should fit into a 200x200 rectangle.
So I don't want to reject some images because they're too big.

@RazrFalcon
Copy link
Owner

Isn't this exactly what the current --width + --height attributes are doing?

@totoestcontent
Copy link
Author

Not exactly.

With image 900_600.svg if i call: resvg --width 200 900_600.svg 900_600_width_200.png , png has dimension: 200x134
With image 32x32.svg if i call: resvg --width 200 32_32.svg 32_32_width_200.png, png has dimension: 200x200,
with --max-width, i want: 200x134 and 32x32
900_600
32_32
900_600_width_200 svg
32_32_width_200 svg

@totoestcontent
Copy link
Author

And if i use --width and --height as
resvg.exe --width 200 --height 200 32_32.svg 32_32_width_200.svg.png
png has dimension: 200x200 and not 32x32.

maybe the problem is elsewhere and the method tiny_skia::size::scale_to doesn't do exactly what it suggests...

@RazrFalcon
Copy link
Owner

Oh, so you do not what to upscale the SVG, only downscale it. I get it now.
Yes, this is not supported. Will think how it could be done.
To me, the main issue is naming, since when I see --max-width I think the max limit, a cut off, which is not what you want. I do plan an option that would return an error when the limit is reached.
It's more like --width-limit to me. Or maybe even --downscale-only.

PS: you can easily achieve what you want from code, obviously. But it would take some time to add to the CLI.

@totoestcontent
Copy link
Author

Thank you for being so responsive.

Indeed, the name of my parameter can be confusing.
I suggested this parameter name in reference to the max-width/height CSS property.

You are better placed than me to choose a name :) .

@RazrFalcon
Copy link
Owner

I suggested this parameter name in reference to the max-width/height CSS property.

Interesting, so those CSS properties do work as you want? I'm not a web developer, so I'm not very familiar with CSS.
If so, then we definitely should use them for consistency.

@totoestcontent
Copy link
Author

Yes these CSS properties do exactly that.
They resize the image to fit within a maximum rectangle.
Proportionality is preserved.
Image is not enlarged if it is smaller.

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

No branches or pull requests

2 participants