File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
SDWebImageSVGCoder/Classes Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,18 @@ - (UIImage *)createBitmapSVGWithData:(nonnull NSData *)data targetSize:(CGSize)t
200200
201201 CGFloat xRatio = targetRect.size .width / rect.size .width ;
202202 CGFloat yRatio = targetRect.size .height / rect.size .height ;
203+
204+ // If we specify only one length of the size (width or height) we want to keep the ratio for that length
205+ if (preserveAspectRatio) {
206+ if (xRatio <= 0 ) {
207+ xRatio = yRatio;
208+ targetRect.size = CGSizeMake (rect.size .width * xRatio, targetSize.height );
209+ } else if (yRatio <= 0 ) {
210+ yRatio = xRatio;
211+ targetRect.size = CGSizeMake (targetSize.width , rect.size .height * yRatio);
212+ }
213+ }
214+
203215 CGFloat xScale = preserveAspectRatio ? MIN (xRatio, yRatio) : xRatio;
204216 CGFloat yScale = preserveAspectRatio ? MIN (xRatio, yRatio) : yRatio;
205217
You can’t perform that action at this time.
0 commit comments