-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
PDFImage quality does not work as expected #78
Comments
Fixed in release 1.1.2 |
just a question: so |
The image is resized in any case to fit the given frame, therefore TPPDF has to calculate and convert anyway. |
this is not exactly what I want there was this code that makes
I don't see why we can't make it optional with
sorry I didn't read the full implementing so it will be something like that I hope you know what I mean |
I think I do understand what you mean.
enum PDFImageOptimisation {
case .none
case .resize
case .compress
case .all
} Now my question:
|
lets not make it complicated. if you get any image needs resizing then resize do it. in my case I sometimes need to crop, resize and keep ratio, stretch. so it's not about the resizing process but more about not losing the quality in some of the images. So if resized the image already then resizing it again will mean extra un-needed work. I don't see the need of adding any extra option. But if you really really want to do this
|
So it is about not modifying the image if not necessary. Sounds reasonable. I like the |
Can you please take a look at the latest commit in the develop branch and let me know about your thoughts. |
You did a great job thank you man! Just a small question: do you think that it might be better to separate the implementation of resize and compress? Here is what I mean instead of this: static func resizeAndCompressImage(image: UIImage, frame: CGRect, shouldResize: Bool, shouldCompress: Bool, quality: CGFloat) -> UIImage use this: static func resize(image: UIImage, frame: CGRect, quality: CGFloat) -> UIImage {
let factor: CGFloat = min(3 * quality, 1)
let resizeFactor = factor.isZero ? 0.2 : factor
let size = CGSize(width: frame.width * resizeFactor, height: frame.height * resizeFactor)
UIGraphicsBeginImageContext(size)
image.draw(in: CGRect(origin: .zero, size: size))
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return finalImage ?? image
}
static func compress(image: UIImage, quality: CGFloat) -> UIImage {
guard let data = UIImageJPEGRepresentation(image, quality) else { return image }
guard let compressed = UIImage(data: data) else { return image }
return compressed
} so it can be easily used as a different action and it will be scalable (if someone asked for crop action or something else) |
Great input! Thank you! I am preparing a release 1.2.0 right now, going to be available soon! |
From the documentation:
But the current behaviour is
expected behaviour
The text was updated successfully, but these errors were encountered: