-
Notifications
You must be signed in to change notification settings - Fork 632
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
ImageOutputFormat should be used everywhere or nowhere #1481
Comments
In the first case (Pro): Also, API usability is improved by the fact that a user cannot accidentally try to write an image with an unsupported ImageFormat. Explicitly declaring an ImageOutputFormat catches the error that a certain image format can not (yet) be written, ahead of runtime. In the second case (Not Cons): Given you want your image to be decoded with a jpeg quality of 80, you already know you need a Jpeg Encoder, so it would be okay to have to work with an image encoder directly, right? |
Yeah, working with a Jpeg Encoder shouldn't be too much of a big deal. Just: Your point about not accidentally trying to write an image with an unsupported format is a good one. Makes me torn between that and the opportunity to reduce the API surface. |
Just hypothetically, if one were to keep ImageOutputFormat and then rename ImageFormat to ImageInputFormat, would this be an obvious change? Or does the ImageFormat currently have more responsibilities than a hypothetical ImageInputFormat? |
Off hand I don't recall anything else that |
That might be true. If we are going for breaking changes anyways, we could point users to |
Hi, confused client here. I want to write out configurable compression JPEGs and PNGs in my program. Currently, I use save method on imagebuffer that does not take any arguments(see #1461 for context). Could you please advise what is the simplest way to go about it? |
@ror6ax the API isn't great right now, but given a DynamicImage something like this should work: let mut encoded = Vec::new();
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut encoded, 95)
.encode(img.as_bytes(), img.width(), img.height(), img.color()).unwrap();
std::fs::write("img.jpeg", encoded).unwrap(); |
@fintelia I'm getting the |
With an ImageBuffer, the encode call should look something like:
|
Still getting
|
That's because encode is a method on JpegEncoder. Here's a playground link with the full code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c84168946cbb374e745e84bdda08c10f |
Thanks, got it working now. |
See image-rs/image#1481 for context about the deprecation of `ImageOutputFormat` and why `ImageFormat` is a good replacement.
See image-rs/image#1481 for context about the deprecation of `ImageOutputFormat` and why `ImageFormat` is a good replacement.
See image-rs/image#1481 for context about the deprecation of `ImageOutputFormat` and why `ImageFormat` is a good replacement.
See image-rs/image#1481 for context about the deprecation of `ImageOutputFormat` and why `ImageFormat` is a good replacement.
Yes, I love it when minor versions break stuff. See image-rs/image#1481
Right now, the
ImageOutputFormat
enum is only used byDynamicImage::write_to
, whereas everywhere else that we encode image files takes an instance of theImageFormat
enum. This distinction has led to confusion (see #1461) and is an API inconsistency. I see two possible ways to resolve this:Use ImageOutputFormat everywhere. This was attempted by @johannesvollmer who provided a possible patch in Require Seekable Writer #1477 (comment). May also want to implement An improved
ImageOutputFormat
design #1380 at the same time to avoid more API breakage in the future.Change
DynamicImage::write_to
to take a ImageFormat, and remove ImageOutputFormat entirely.The text was updated successfully, but these errors were encountered: