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

Check mime type of picture instead of filename extension #74

Closed
Aleksanaa opened this issue Jan 23, 2023 · 2 comments · Fixed by #76
Closed

Check mime type of picture instead of filename extension #74

Aleksanaa opened this issue Jan 23, 2023 · 2 comments · Fixed by #76
Labels
enhancement New feature or request

Comments

@Aleksanaa
Copy link

For some reasons we may wish to set wallpapers with no filename extension (for example, I have a script to move wallpaper to ~/.local/share/background ) . However, swww refuses to use such files, throwing Error: "failed to open image '\"/home/aleksana/.local/share/background\"': The image format could not be determined".

In most cases on desktop linux, we do not determine file by its filename extension, but use mine types instead. You can use file --mime-type foo.bar to view a file's type.

@Aleksanaa
Copy link
Author

The related code is in src/main.rs#L142, and the docs suggests .with_guessed_format(). I didn't make a pull request because I don't have a knowledge of writing rust at all. Please test it if possible.

@Aleksanaa
Copy link
Author

Okay so I ended up writing this patch on my own (This is for 0.6.0, as master is unusable when I test it)

--- a/src/daemon/processor/mod.rs
+++ b/src/daemon/processor/mod.rs

@@ -138,7 +138,8 @@ impl Processor {
 
     pub fn process(&mut self, requests: Vec<ProcessorRequest>) -> Answer {
         for request in requests {
-            let img = match image::open(&request.path) {
+            let mut reader = image::io::Reader::open(&request.path).expect("idk").with_guessed_format().expect("The image format could not be determined");
+            let img = match reader.decode() {
                 Ok(i) => i.into_rgba8(),
                 Err(e) => {
                     return Answer::Err(format!(

@LGFae LGFae added the enhancement New feature or request label Jan 25, 2023
@LGFae LGFae closed this as completed in #76 Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants