Skip to content

Commit

Permalink
fix: image.size incorrect if initialized from data
Browse files Browse the repository at this point in the history
  • Loading branch information
relikd committed Mar 21, 2024
1 parent c179fb1 commit dfd81d4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ProvisionQL/AppIcon.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,20 @@ + (NSBezierPath *)bezierPathWithIOS7RoundedRect:(NSRect)rect cornerRadius:(CGFlo

@implementation NSImage (AppIcon)

/// Because some (PNG) image data will return weird float values
- (NSSize)bestImageSize {
NSInteger w = self.size.width;
NSInteger h = self.size.height;
for (NSImageRep * imageRep in [self representations]) {
w = MAX(w, [imageRep pixelsWide]);
h = MAX(h, [imageRep pixelsHigh]);
}
return NSMakeSize(w, h);
}

/// Apply rounded corners to image (iOS7 style)
- (NSImage * _Nonnull)withRoundCorners {
NSSize existingSize = [self size];
NSSize existingSize = [self bestImageSize];
NSImage *composedImage = [[NSImage alloc] initWithSize:existingSize];

[composedImage lockFocus];
Expand All @@ -385,7 +396,7 @@ - (NSImage * _Nonnull)withRoundCorners {
[clipPath setWindingRule:NSWindingRuleEvenOdd];
[clipPath addClip];

[self drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0, 0, existingSize.width, existingSize.height) operation:NSCompositingOperationSourceOver fraction:1];
[self drawInRect:imageFrame];
[composedImage unlockFocus];
return composedImage;
}
Expand Down

0 comments on commit dfd81d4

Please sign in to comment.