Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Was hoping that someone knew any software or maybe a script that can validate a wallpaper resolution and sort out the valid images.
I made a bash script that calculated the image aspect ratio and checked that against 4:3 and 16:9.
But as I noticed there are a lot of small resolutions that still validate, and a lot of large ones that don't.
Instead of adding them all and checking for a minimum width/height I thought I could ask here.
The problem is that I have a folder filled with images that claim to be wallpapers but I know some of them are not, since some have a higher height than width and some just have a very strange resolution.
So a software or a script that can validate the resolution or aspect ratio against valid ones would be great.
Hope someone can help...
Using something like this, it would make a lot of sense to put the parsing code in a bash function.
It would hide the dirty details in your main script. You could have one function width() and another one height() and then use the functions in a numerical test. This would make your main code very readable.
This is how my bash script looks today. Not much but it seems to do the trick, but as said before I need a better working check.
Code:
#!/bin/bash
find . -type f -name '*.jpg' | sort | while read file
do
set -- $(identify -format "%w %h" -quiet "$file")
calculation=$(echo "scale=10; $1 / $2" | bc -l)
if ! [ $calculation == "1.3333333333" -o $calculation == "1.7777777777" ]
then
echo "File '${file}' has the wrong aspect ratio (${1}x${2} - ${calculation}).";
fi
done
Can you find anything special with the files that fail? It would be interesting seeing the height and width values for the files that fail, because as long as the output from identify is correct your script seems quite solid.
select from a set of possibles is what "case" does
Quote:
Originally Posted by XeroXer
I added support for some other aspect ratios. This script seems to work just as I want...
Code:
#!/bin/bash
# 4:3 - 1.3333333333
# 5:4 - 1.2500000000
# 16:9 - 1.7777777777
# 16:10 - 1.6000000000
...
if ! [ $calculation == "1.3333333333" -o
$calculation == "1.2500000000" -o
$calculation == "1.7777777777" -o
$calculation == "1.6000000000" ]
then
echo "File '${file}' has the wrong aspect ratio (${1}x${2} - ${calculation}).";
fi
...
Consider something like this:
Code:
...
FOUR_BY_THREE="1.3333333333"
FIVE_BY_FOUR="1.2500000000"
WIDE_BY_NINE="1.7777777777"
WIDE_BY_TEN="1.6000000000"
...
calculation=$( ... )
case "$calculation" in
"$FOUR_BY_THREE")
"$FIVE_BY_FOUR")
"$WIDE_BY_NINE")
"$WIDE_BY_TEN")
echo "... do this for good ratios"
;;
*)
echo "??? do this for wrong ratios"
;;
esac
...
It makes the code more readable, easier to maintain, and so on.
Sorry, I'm not a shell programming maven so my code describes an intention not a working implementation.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.