Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
use crate::plugin::Plugin;
|
||||
use image::ImageFormat;
|
||||
use std::io::Cursor;
|
||||
|
||||
pub struct PluginImpl;
|
||||
|
||||
impl Plugin for PluginImpl {
|
||||
fn name(&self) -> &'static str { "png_to_jpeg" }
|
||||
fn from_formats(&self) -> Vec<&'static str> { vec!["png"] }
|
||||
fn to_formats(&self) -> Vec<&'static str> { vec!["jpeg"] }
|
||||
fn familiarity(&self) -> u8 { 255 }
|
||||
fn quality(&self) -> u8 { 200 } // JPEG has some compression loss
|
||||
fn speed(&self) -> u8 { 220 }
|
||||
|
||||
fn convert(&self, input: &[u8], _from: &str, _to: &str) -> Result<Vec<u8>, String> {
|
||||
let img = image::load_from_memory_with_format(input, ImageFormat::Png)
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut buf = Vec::new();
|
||||
img.write_to(&mut Cursor::new(&mut buf), ImageFormat::Jpeg)
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user