Update dependencies and restrict writers to implement Seek as well

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

@ -4,21 +4,21 @@ readme = "README.md"
license = "Apache-2.0"
authors = ["trivernis <trivernis@protonmail.com>"]
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"]

@ -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<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());
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<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());
image.write_to(writer, ImageOutputFormat::Jpeg(compression))?;

@ -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())
}

Loading…
Cancel
Save