-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
Make initializer failable in case the pixel format is unsupported #129
Conversation
1f3a37c
to
3465751
Compare
…s for image source creation Fix crash on extreme aspect ratios images
let targetSize: CGSize = { | ||
imageSize.scaled(maxPixelSize: maxPixelSize) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ntnmrndn
any reason? but I don't care
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore. I edited it
|
||
/// Checks that the pixel format is supported by core graphics. | ||
/// Throws in case an error is found. | ||
public static func validatePixelFormat(_ image: UIImage) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
public static func makeResizedCGImage( | ||
from sourceImage: CGImage, | ||
maxPixelSizeHint: CGFloat | ||
) -> CGImage? { | ||
let maxPixelSize: CGFloat = { | ||
let largestSide = max(sourceImage.size.width, sourceImage.size.height) | ||
let smallestSide = min(sourceImage.size.width, sourceImage.size.height) | ||
guard smallestSide >= maxPixelSizeHint else { | ||
return largestSide | ||
} | ||
return largestSide * maxPixelSizeHint / smallestSide | ||
}() | ||
return makeResizedCGImage(from: sourceImage, maxPixelSize: maxPixelSize) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for fixing it.
Should we make the original one internal method? is it okay to keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which means, integrating this operation and below primitive operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it's ok to have both; since they do different things. If an user is confident that his image can use the maxPixelSize
version it's ok to use it.
No description provided.