Skip to content
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

Deprecate compound input fn in favor of Reader #1327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/dynimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,13 @@ fn image_to_bytes(image: &DynamicImage) -> Vec<u8> {
/// content before its path.
///
/// [`io::Reader`]: io/struct.Reader.html
#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."]
pub fn open<P>(path: P) -> ImageResult<DynamicImage>
where
P: AsRef<Path>,
{
// thin wrapper function to strip generics before calling open_impl
free_functions::open_impl(path.as_ref())
crate::io::Reader::open(path)?
.decode()
}

/// Read the dimensions of the image located at the specified path.
Expand All @@ -1003,12 +1004,13 @@ where
/// content before its path or manually supplying the format.
///
/// [`io::Reader`]: io/struct.Reader.html
#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."]
pub fn image_dimensions<P>(path: P) -> ImageResult<(u32, u32)>
where
P: AsRef<Path>,
{
// thin wrapper function to strip generics before calling open_impl
free_functions::image_dimensions_impl(path.as_ref())
crate::io::Reader::open(path)?
.into_dimensions()
}

/// Saves the supplied buffer to a file at the path specified.
Expand Down Expand Up @@ -1063,9 +1065,12 @@ where
/// Try [`io::Reader`] for more advanced uses.
///
/// [`io::Reader`]: io/struct.Reader.html
#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."]
pub fn load_from_memory(buffer: &[u8]) -> ImageResult<DynamicImage> {
let format = free_functions::guess_format(buffer)?;
load_from_memory_with_format(buffer, format)
let b = io::Cursor::new(buffer);
crate::io::Reader::new(b)
.with_guessed_format()?
.decode()
}

/// Create a new image from a byte slice
Expand All @@ -1078,9 +1083,10 @@ pub fn load_from_memory(buffer: &[u8]) -> ImageResult<DynamicImage> {
/// [`load`]: fn.load.html
/// [`io::Reader`]: io/struct.Reader.html
#[inline(always)]
pub fn load_from_memory_with_format(buf: &[u8], format: ImageFormat) -> ImageResult<DynamicImage> {
let b = io::Cursor::new(buf);
free_functions::load(b, format)
#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."]
pub fn load_from_memory_with_format(buffer: &[u8], format: ImageFormat) -> ImageResult<DynamicImage> {
let b = io::Cursor::new(buffer);
crate::io::Reader::with_format(b, format).decode()
}

/// Calculates the width and height an image should be resized to.
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#![cfg_attr(all(test, feature = "benchmarks"), feature(test))]
// it's a bit of a pain otherwise
#![allow(clippy::many_single_char_names)]
#![cfg_attr(test, allow(deprecated))]

#[cfg(all(test, feature = "benchmarks"))]
extern crate test;
Expand Down Expand Up @@ -170,6 +171,7 @@ pub use crate::traits::{EncodableLayout, Primitive, Pixel};

// Opening and loading images
pub use crate::io::free_functions::{guess_format, load};
#[allow(deprecated)]
pub use crate::dynimage::{load_from_memory, load_from_memory_with_format, open,
save_buffer, save_buffer_with_format, image_dimensions};

Expand Down