Skip to content

Commit

Permalink
fix: image format
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jul 16, 2023
1 parent 0766e37 commit 4af52c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/core/tasks/precache.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))?;
}
Expand Down
11 changes: 10 additions & 1 deletion src/core/tasks/process.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::process::Stdio;

use anyhow::Result;
use tokio::{process::Command, select, sync::{mpsc, oneshot}};
use tracing::trace;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 4af52c7

Please sign in to comment.