Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

266 bug filenames with dots result in incorrect output names #268

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/cli/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn decode<P: AsRef<Path>>(f: P) -> Result<Image, ImageErrors> {
let mut file_content = vec![];

file.read_to_end(&mut file_content)?;
file.seek(SeekFrom::Start(0))?;

if libavif::is_avif(&file_content) {
use rimage::codecs::avif::AvifDecoder;
Expand All @@ -42,32 +43,39 @@ pub fn decode<P: AsRef<Path>>(f: P) -> Result<Image, ImageErrors> {

return Image::from_decoder(decoder);
};

file.seek(SeekFrom::Start(0))?;
}

#[cfg(feature = "webp")]
if f.as_ref()
.extension()
.is_some_and(|f| f.eq_ignore_ascii_case("webp"))
{
use rimage::codecs::webp::WebPDecoder;
if f.as_ref()
.extension()
.is_some_and(|f| f.eq_ignore_ascii_case("webp"))
{
use rimage::codecs::webp::WebPDecoder;

let decoder = WebPDecoder::try_new(file)?;
let decoder = WebPDecoder::try_new(file)?;

return Image::from_decoder(decoder);
};
return Image::from_decoder(decoder);
}

file.seek(SeekFrom::Start(0))?;
}

#[cfg(feature = "tiff")]
if f.as_ref()
.extension()
.is_some_and(|f| f.eq_ignore_ascii_case("tiff") | f.eq_ignore_ascii_case("tif"))
{
use rimage::codecs::tiff::TiffDecoder;
if f.as_ref()
.extension()
.is_some_and(|f| f.eq_ignore_ascii_case("tiff") | f.eq_ignore_ascii_case("tif"))
{
use rimage::codecs::tiff::TiffDecoder;

let decoder = TiffDecoder::try_new(file)?;

let decoder = TiffDecoder::try_new(file)?;
return Image::from_decoder(decoder);
}

return Image::from_decoder(decoder);
file.seek(SeekFrom::Start(0))?;
}

Err(ImageErrors::ImageDecoderNotImplemented(
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ fn main() {
pb.set_style(sty_aux_operations.clone());

let mut available_encoder = handle_error!(input, encoder(subcommand, matches));
output.set_extension(available_encoder.to_extension());
if let Some(ext) = output.extension() {
output.set_extension({
let mut os_str = ext.to_os_string();
os_str.push(".");
os_str.push(available_encoder.to_extension());
os_str
});
} else {
output.set_extension(available_encoder.to_extension());
}

pipeline.chain_operations(Box::new(Depth::new(BitDepth::Eight)));
pipeline.chain_operations(Box::new(ColorspaceConv::new(ColorSpace::RGBA)));
Expand Down