Update dependencies and restrict writers to implement Seek as well

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 2 years ago
parent 5017e26991
commit bdc3ae07ac
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -4,21 +4,21 @@ readme = "README.md"
license = "Apache-2.0" license = "Apache-2.0"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
description = "An image thumbnail creation library" description = "An image thumbnail creation library"
version = "0.2.5" version = "0.3.0"
edition = "2018" edition = "2018"
repository = "https://github.com/Trivernis/thumbnailer" repository = "https://github.com/Trivernis/thumbnailer"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
webp = "0.2.0" webp = "^0.2.1"
mime = "0.3.16" mime = "^0.3.16"
rayon = "1.5.1" rayon = "^1.5.1"
ffmpeg-next = {version = "4.4.0", optional=true} ffmpeg-next = {version = "^4.4.0", optional=true}
tempfile = "3.2.0" tempfile = "^3.3.0"
[dependencies.image] [dependencies.image]
version = "0.23.14" version = "^0.24.0"
[features] [features]
default = ["ffmpeg"] default = ["ffmpeg"]

@ -7,6 +7,7 @@
//! use thumbnailer::{create_thumbnails, Thumbnail, ThumbnailSize}; //! use thumbnailer::{create_thumbnails, Thumbnail, ThumbnailSize};
//! use std::fs::File; //! use std::fs::File;
//! use std::io::BufReader; //! use std::io::BufReader;
//! use std::io::Cursor;
//! //!
//! fn main() { //! fn main() {
//! let file = File::open("tests/assets/test.png").unwrap(); //! 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 mut thumbnails = create_thumbnails(reader, mime::IMAGE_PNG, [ThumbnailSize::Small, ThumbnailSize::Medium]).unwrap();
//! //!
//! let thumbnail = thumbnails.pop().unwrap(); //! let thumbnail = thumbnails.pop().unwrap();
//! let mut buf = Vec::new(); //! let mut buf = Cursor::new(Vec::new());
//! thumbnail.write_png(&mut buf).unwrap(); //! thumbnail.write_png(&mut buf).unwrap();
//! } //! }
//! ``` //! ```
@ -41,7 +42,7 @@ pub struct Thumbnail {
impl Thumbnail { impl Thumbnail {
/// Writes the bytes of the image in a png format /// Writes the bytes of the image in a png format
pub fn write_png<W: Write>(self, writer: &mut W) -> ThumbResult<()> { pub fn write_png<W: Write + Seek>(self, writer: &mut W) -> ThumbResult<()> {
let image = DynamicImage::ImageRgba8(self.inner.into_rgba8()); let image = DynamicImage::ImageRgba8(self.inner.into_rgba8());
image.write_to(writer, ImageOutputFormat::Png)?; image.write_to(writer, ImageOutputFormat::Png)?;
@ -49,7 +50,7 @@ impl Thumbnail {
} }
/// Writes the bytes of the image in a jpeg format /// Writes the bytes of the image in a jpeg format
pub fn write_jpeg<W: Write>(self, writer: &mut W, compression: u8) -> ThumbResult<()> { pub fn write_jpeg<W: Write + Seek>(self, writer: &mut W, compression: u8) -> ThumbResult<()> {
let image = DynamicImage::ImageRgb8(self.inner.into_rgb8()); let image = DynamicImage::ImageRgb8(self.inner.into_rgb8());
image.write_to(writer, ImageOutputFormat::Jpeg(compression))?; image.write_to(writer, ImageOutputFormat::Jpeg(compression))?;

@ -71,11 +71,11 @@ fn write_thumbnail(
.pop() .pop()
.unwrap(); .unwrap();
let mut buf = Vec::new(); let mut buf = Cursor::new(Vec::new());
match target_format { match target_format {
TargetFormat::Png => thumb.write_png(&mut buf)?, TargetFormat::Png => thumb.write_png(&mut buf)?,
TargetFormat::Jpeg => thumb.write_jpeg(&mut buf, 8)?, TargetFormat::Jpeg => thumb.write_jpeg(&mut buf, 8)?,
} }
Ok(buf) Ok(buf.into_inner())
} }

Loading…
Cancel
Save