Saturday, December 29, 2007

Find images of certain size and copy them to some directory

Let us say you wanna find images of width 640 so you copy them to a separate directory for further processing. How can you do that?
Here is one way to do it
First, you have to find out the files with width 640. Second, copy them.

To find out file of certain size you can use the command identify

$ identify 0100.jpg
0100.jpg JPEG 378x251 PseudoClass 256c 9kb

Now, when u do
$ identify*.jpg | grep 640
new_0100-0.jpg[451] JPEG 640x425 PseudoClass 256c 16kb
new_0101-0.jpg[453] JPEG 640x425 PseudoClass 256c 22kb
new_0102-0.jpg[455] JPEG 640x425 PseudoClass 256c 24kb
new_0103-0.jpg[457] JPEG 640x425 PseudoClass 256c 26kb
new_0104-0.jpg[459] JPEG 640x425 PseudoClass 256c 12kb
new_0105-0.jpg[461] JPEG 640x425 PseudoClass 256c 23kb
new_0106-0.jpg[463] JPEG 640x425 PseudoClass 256c 20kb
new_0107-0.jpg[465] JPEG 640x425 PseudoClass 256c 24kb
new_0108-0.jpg[467] JPEG 640x425 PseudoClass 256c 17kb
new_0109-0.jpg[469] JPEG 640x425 PseudoClass 256c 28kb
new_0110-0.jpg[471] JPEG 640x425 PseudoClass 256c 31kb
new_0111-0.jpg[473] JPEG 640x425 PseudoClass 256c 36kb
new_0112-0.jpg[475] JPEG 640x425 PseudoClass 256c 27kb
new_0113-0.jpg[477] JPEG 640x425 PseudoClass 256c 25kb

so we do this and save the output in the file files
identify *.jpg | grep 640 | cut -f 1 -d [ > files

Finally
for i in `cat files`; do cp $i directory_640/; done

No comments: