fix: image format

This commit is contained in:
sxyazi 2023-07-17 00:00:26 +08:00
parent 0766e37100
commit 4af52c74fb
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View file

@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use anyhow::Result;
use image::imageops::FilterType;
use image::{imageops::FilterType, ImageFormat};
use tokio::{fs, sync::mpsc};
use super::TaskOp;
@ -68,10 +68,8 @@ impl Precache {
};
let (w, h) = (PREVIEW.max_width, PREVIEW.max_height);
if img.width() <= w && img.height() <= h {
img.save(cache).ok();
} else {
img.resize(w, h, FilterType::Triangle).save(cache).ok();
if img.width() > w || img.height() > h {
img.resize(w, h, FilterType::Triangle).save_with_format(&cache, ImageFormat::Jpeg).ok();
}
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
}

View file

@ -1,3 +1,5 @@
use std::process::Stdio;
use anyhow::Result;
use tokio::{process::Command, select, sync::{mpsc, oneshot}};
use tracing::trace;
@ -44,9 +46,16 @@ impl Process {
ProcessOp::Open(task) => {
trace!("Open task: {:?}", task);
if !task.block {
let status = Command::new(&task.cmd)
.args(&task.args)
.stdout(Stdio::null())
.stderr(Stdio::null())
.kill_on_drop(true)
.status();
select! {
_ = task.cancel.closed() => {},
Ok(status) = Command::new(&task.cmd).args(&task.args).kill_on_drop(true).status() => {
Ok(status) = status => {
trace!("{} exited with {:?}", task.cmd, status);
}
}