LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2010, 12:42 PM   #1
Huwie
LQ Newbie
 
Registered: Mar 2006
Distribution: Sabayon
Posts: 7

Rep: Reputation: 0
Finding images based on their dimensions


Hi everyone

I'm not afraid of bash but I'm not very good with it either. I'm assuming there's a way of using find, perhaps in conjunction with another tool, to find images in a directory (and subdirectories) based on their dimensions?

Specifically, I want to find all the landscape-oriented images and copy them somewhere else.

Thanks in advance for any help.
 
Old 11-05-2010, 01:08 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
find . -name "*.jpg" | while read picture; do
     xdim=$(identify "$picture" | awk '{print $3}' | awk -Fx '{print $1}')
     ydim=$(identify "$picture" | awk '{print $3}' | awk -Fx '{print $2}')
     [ $xdim -gt $ydim ] && cp "$picture" "/path/to/destination/directory"
done
The above is just a modified version of some code I posted over here in post #7:
http://www.linuxquestions.org/questi...s-pngs-796781/

I adjusted it to simply compare the X dimension of the image with the Y dimension; if X is larger, copy the image somewhere else. You'd need to put the right path to your target directory, and adjust the -name parameter to the `find` command to search for the filename pattern you desire.
I haven't tested it so maybe try it on a test directory first, though it won't delete anything by accident even if it doesn't work as expected.
You'll need ImageMagick tools installed to have the `identify` command.

Good luck!
 
1 members found this post helpful.
Old 11-05-2010, 01:13 PM   #3
Huwie
LQ Newbie
 
Registered: Mar 2006
Distribution: Sabayon
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you very much for your reply, Celine! I'm very grateful for your help. I don't know what most of that code means so I'll do some reading up on it, and I'll let you know if it works.
 
Old 11-05-2010, 01:16 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
No problem - any questions, just ask and I or someone will try to answer. The only man pages you need to reference (besides Bash itself) are for the `find` command, as well as `awk` and `identify`. The awk commands just return the desired column (field) of each input, so to see the effect of this, try in a console, using the `identify` command by itself on a picture; then, try it but pipe it into some awk and see what comes out. You should then understand about the fields.
EDIT: Oh, and there's the `cp` command of course, so if you want to use a different `cp` syntax, check the `cp` manpage too.

Anyhow, any questions, feel free to ask.

Cheers!

Last edited by GrapefruiTgirl; 11-05-2010 at 01:29 PM.
 
1 members found this post helpful.
Old 11-06-2010, 03:03 AM   #5
Huwie
LQ Newbie
 
Registered: Mar 2006
Distribution: Sabayon
Posts: 7

Original Poster
Rep: Reputation: 0
Yep, it works like a charm. Thanks so much Celine, you've saved me a lot of laborious work!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
need help finding a particular linux-based handheld PC Dralnu Linux - General 1 10-26-2010 10:48 AM
Finding copies of files based on MD5SUM. bluesword1969 Programming 5 07-15-2010 10:38 AM
Finding a wireless card based on Intel IPW2200 azrael808 Linux - Hardware 0 04-24-2005 08:16 AM
Finding all the images on a site. PeterWelzien Linux - Networking 7 10-27-2004 03:21 AM
Finding files based on content benjaminrtz Linux - General 2 08-04-2002 11:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration