SDWebImage / SDWebImageSVGCoder

A SVG coder plugin for SDWebImage, using Apple's built-in framework
MIT License
103 stars 34 forks source link

Allow constraining bitmap on one length only (width or height) #28

Closed Maxador closed 3 years ago

Maxador commented 3 years ago

Fix: https://github.com/SDWebImage/SDWebImageSVGCoder/issues/27

All the svgs are constrained to 34pt high Simulator Screen Shot - Apple Watch Series 6 - 44mm - 2020-12-11 at 11 25 11

dreampiggy commented 3 years ago

This sounds like new feature request.

Any better idea instead of this sucking length == 0 means keep length and use aspect ratio ? This sounds not a good design.


If we have no other good solution to let user provide this context (I want to keep length limit, width based on calculation), maybe this is the only way.

dreampiggy commented 3 years ago

And if you change this, we'd better update the code and comments in both https://github.com/SDWebImage/SDWebImagePDFCoder and https://github.com/SDWebImage/SDWebImage.

dreampiggy commented 3 years ago

I'll decide to merge this and update code comments as well. Then I need to sync this PR into SDWebImage Core and SDWebImagePDFCoder (Another vector format), which have the same use case.

dreampiggy commented 3 years ago

@Maxador I extend the both preserve aspect ratio and non-preserve aspect ratio cases for 0 length. See #29

Maxador commented 3 years ago

Very nice! Thank you! For adding to your suggestion of not hijacking the Size context for that, we could add a new context option. Something like LengthConstraint that could take a length type (enum for width or height) and a length value (CGFloat).

dreampiggy commented 3 years ago

For SVG bitmap image (such as watchOS), new version available in 1.6.0

If you want to keep aspect ratio, and does not know about What's the size of this SVG URL ? this inforamtion. You can provide width or height to 0, which means ignore the limit.

See more complicated rules in README-Render SVG as bitmap image