LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 11-13-2009, 03:09 AM   #1
XeroXer
LQ Newbie
 
Registered: Jun 2008
Location: Västerås, Sweden
Distribution: Arch Linux, Debian, Ubuntu
Posts: 21

Rep: Reputation: 16
Question Find valid wallpapers by resolution


Hi all!

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...
 
Old 11-13-2009, 04:29 AM   #2
jswetzen
LQ Newbie
 
Registered: Nov 2009
Distribution: Ubuntu
Posts: 4

Rep: Reputation: 0
I'd go for a bash script, it seems simple enough. If you post your script here, I could have a look at it.
 
Old 11-13-2009, 04:44 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Mediainfo will report the resolution of pictures and videos. You can use sed or awk to extract the info you need and assign the result to a variable.

The ImageMagic package includes the `identify' command which supplies information on images that would be easier to extract.

Code:
> identify work/roseb.eps
work/roseb.eps PS 612x792 612x792+0+0 16-bit DirectClass 9.55kb

> identify work/roseb.eps | 
sed 's/.* [A-Z][A-Z]* \([[:digit:]][[:digit:]]*\)x\([[:digit:]][[:digit:]]*\) .*/width=\1\nheight=\2\n/'
width=612
height=792

> eval $(identify work/roseb.eps | sed 's/.* [A-Z][A-Z]* \([[:digit:]][[:digit:]]*\)x\([[:digit:]][[:digit:]]*\) .*/width=\1\nheight=\2\n/')
> echo $width
612
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.

Last edited by jschiwal; 11-13-2009 at 04:48 AM.
 
Old 11-13-2009, 06:34 AM   #4
XeroXer
LQ Newbie
 
Registered: Jun 2008
Location: Västerås, Sweden
Distribution: Arch Linux, Debian, Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 16
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
 
Old 11-15-2009, 11:12 AM   #5
jswetzen
LQ Newbie
 
Registered: Nov 2009
Distribution: Ubuntu
Posts: 4

Rep: Reputation: 0
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.
 
Old 11-15-2009, 01:26 PM   #6
XeroXer
LQ Newbie
 
Registered: Jun 2008
Location: Västerås, Sweden
Distribution: Arch Linux, Debian, Ubuntu
Posts: 21

Original Poster
Rep: Reputation: 16
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
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.2500000000" -o $calculation == "1.7777777777" -o $calculation == "1.6000000000" ]
    then
        echo "File '${file}' has the wrong aspect ratio (${1}x${2} - ${calculation}).";
    fi
done
 
Old 11-15-2009, 02:21 PM   #7
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
select from a set of possibles is what "case" does

Quote:
Originally Posted by XeroXer View Post
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.

~~~ 0;-Dan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot find a valid baseurl for repo: extras anshexp Linux - Software 4 08-01-2009 10:33 PM
Cannot find a valid baseurl for repo: core navy319510 Linux - Software 2 08-03-2006 05:33 AM
Where can I find nice wallpapers and/or icons? firedance Linux - General 1 11-04-2005 03:02 PM
cannot find valid hard drives msriram_linux Linux - Hardware 2 05-21-2005 09:29 AM
not a valid block device..... where do I find it? rkhartley Linux - Newbie 6 12-11-2003 10:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration