Skip to content

Instantly share code, notes, and snippets.

@Nua07
Last active March 18, 2021 06:46
Show Gist options
  • Save Nua07/1ba75be33c94a9aa899bc88f753fe86b to your computer and use it in GitHub Desktop.
Save Nua07/1ba75be33c94a9aa899bc88f753fe86b to your computer and use it in GitHub Desktop.
use std::fs::File;
use std::io::Read;
use std::io::Write;
use std::process::Stdio;
use std::process::Command;
fn webp2gif(data: Vec<u8>) -> Vec<u8> {
let mut conv = Command::new("convert")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.arg("fd:0")
.arg("-delay")
.arg("10")
.arg("-dispose")
.arg("none")
.arg("-coalesce")
.arg("-loop")
.arg("0")
.arg("-background")
.arg("white")
.arg("-alpha")
.arg("remove")
.arg("gif:fd:1")
.spawn()
.unwrap();
{
let stdin = conv.stdin.as_mut().expect("Failed to open stdin");
stdin.write_all(&data).expect("Failed to write to stdin");
}
let output = conv.wait_with_output().expect("Failed to read stdout");
output.stdout
}
fn main() {
let mut f = File::open("input.webp").unwrap();
let mut f1 = File::create("o.gif").unwrap();
let mut v = Vec::new();
f.read_to_end(&mut v).unwrap();
f1.write_all(&webp2gif(v)).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment