Skip to content

Commit 7251c34

Browse files
authored
Merge pull request #28 from Maxador/master
Allow constraining bitmap on one length only (width or height)
2 parents 6301af9 + 58b0b56 commit 7251c34

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

SDWebImageSVGCoder/Classes/SDImageSVGCoder.m

+12
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)