-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, the GIF parser would assume a GIF is animated if it had the Netscape Application Extension. This can lead to false positives where a GIF can have all the indicators of an animated GIF but only one Image Descriptor. Now, the code checks for the absence of the Graphic Control Extension before an Image Descriptor to mean non-animated and otherwise checks if there are multiple Image Descriptors. This unfortunately requires parsing much further into the data stream. The example cli now also supports specifiying the buffer size.
- Loading branch information
Showing
6 changed files
with
314 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
extern crate imgsize; | ||
use clap::Parser; | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::Read; | ||
use std::{env, io}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser)] | ||
struct Arguments { | ||
#[arg(short, long, default_value_t = 1024)] | ||
buf_size: usize, | ||
paths: Vec<PathBuf>, | ||
} | ||
|
||
pub fn main() -> io::Result<()> { | ||
let mut buffer = [0u8; 1024]; | ||
for path in env::args().skip(1) { | ||
let arguments = Arguments::parse(); | ||
let mut buffer = vec![0u8; arguments.buf_size]; | ||
for path in arguments.paths.iter() { | ||
let name = path.to_str().unwrap(); | ||
let mut file = File::open(&path)?; | ||
file.read(&mut buffer)?; | ||
match imgsize::get_size(&buffer) { | ||
let read = file.read(&mut buffer)?; | ||
match imgsize::get_size(&buffer[..read]) { | ||
Some(size) => println!( | ||
"{}: {}x{}, {}, animated={}", | ||
path, size.width, size.height, size.mime_type, size.is_animated | ||
name, size.width, size.height, size.mime_type, size.is_animated | ||
), | ||
None => println!("{}: unsupported format", path), | ||
None => println!("{}: unsupported format", name), | ||
} | ||
buffer.fill(0); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.