From bdc3ae07ac7d396616f33c9095968ac823352e41 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 3 Feb 2022 20:09:35 +0100 Subject: [PATCH] Update dependencies and restrict writers to implement Seek as well Signed-off-by: trivernis --- Cargo.toml | 14 +++++++------- src/lib.rs | 7 ++++--- tests/image_writing.rs | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index de75089..bb29a99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,21 +4,21 @@ readme = "README.md" license = "Apache-2.0" authors = ["trivernis "] description = "An image thumbnail creation library" -version = "0.2.5" +version = "0.3.0" edition = "2018" repository = "https://github.com/Trivernis/thumbnailer" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -webp = "0.2.0" -mime = "0.3.16" -rayon = "1.5.1" -ffmpeg-next = {version = "4.4.0", optional=true} -tempfile = "3.2.0" +webp = "^0.2.1" +mime = "^0.3.16" +rayon = "^1.5.1" +ffmpeg-next = {version = "^4.4.0", optional=true} +tempfile = "^3.3.0" [dependencies.image] -version = "0.23.14" +version = "^0.24.0" [features] default = ["ffmpeg"] diff --git a/src/lib.rs b/src/lib.rs index 891ad4f..f39796d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ //! use thumbnailer::{create_thumbnails, Thumbnail, ThumbnailSize}; //! use std::fs::File; //! use std::io::BufReader; +//! use std::io::Cursor; //! //! fn main() { //! let file = File::open("tests/assets/test.png").unwrap(); @@ -14,7 +15,7 @@ //! let mut thumbnails = create_thumbnails(reader, mime::IMAGE_PNG, [ThumbnailSize::Small, ThumbnailSize::Medium]).unwrap(); //! //! let thumbnail = thumbnails.pop().unwrap(); -//! let mut buf = Vec::new(); +//! let mut buf = Cursor::new(Vec::new()); //! thumbnail.write_png(&mut buf).unwrap(); //! } //! ``` @@ -41,7 +42,7 @@ pub struct Thumbnail { impl Thumbnail { /// Writes the bytes of the image in a png format - pub fn write_png(self, writer: &mut W) -> ThumbResult<()> { + pub fn write_png(self, writer: &mut W) -> ThumbResult<()> { let image = DynamicImage::ImageRgba8(self.inner.into_rgba8()); image.write_to(writer, ImageOutputFormat::Png)?; @@ -49,7 +50,7 @@ impl Thumbnail { } /// Writes the bytes of the image in a jpeg format - pub fn write_jpeg(self, writer: &mut W, compression: u8) -> ThumbResult<()> { + pub fn write_jpeg(self, writer: &mut W, compression: u8) -> ThumbResult<()> { let image = DynamicImage::ImageRgb8(self.inner.into_rgb8()); image.write_to(writer, ImageOutputFormat::Jpeg(compression))?; diff --git a/tests/image_writing.rs b/tests/image_writing.rs index 4e8aa76..7335870 100644 --- a/tests/image_writing.rs +++ b/tests/image_writing.rs @@ -71,11 +71,11 @@ fn write_thumbnail( .pop() .unwrap(); - let mut buf = Vec::new(); + let mut buf = Cursor::new(Vec::new()); match target_format { TargetFormat::Png => thumb.write_png(&mut buf)?, TargetFormat::Jpeg => thumb.write_jpeg(&mut buf, 8)?, } - Ok(buf) + Ok(buf.into_inner()) }