Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

So, I had a relative's hard drive collapse, and I've used photorec to look for the most obvious files to retain (fortunately they only had pictures on the computer, everything else was cloud-synced, such as email) so I now have a parent-folder with 208 subfolders of all the PNG and JPG files from the old drive. Obviously a lot will be either "OS and Application images" (toolbars, sample images, thumbnails, system caches) and some will be "family photos".

If I can find some way to find all below a certain size (preferably say 300px wide) then sorting the rest should * be easy.

How can I use iPhoto or Spotlight or something to do this automatically? I'm also open to scripts using easily installed (brew perhaps?) libraries, if a script of some sort can be pointed to.

* famous last words

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

You can use the terminal to do this. The following command should work:

find /path/to/the/folder \
  -name "*.jpg" \
  -exec bash -c "sips -g pixelHeight -g pixelWidth {} | grep -E ' [12]?[0-9]{0,2}$' >/dev/null" \;\
  -print 

That command will find all JPEG files under /path/to/the/folder which have a width or a height of between 1 and 299 pixels.

Replace /path/to/the/folder with the actual path to your folder.

You can change "*.jpg" to "*.gif" to find GIF files instead.

You can change [12]?[0-9]{0,2} to change the size of the pictures you wish to locate. For example, to find pictures smaller than 500 pixels, use [1234]?[0-9]{0,2}

If you want to review which pictures this command finds, use:

find /path/to/the/folder \
  -name "*.jpg" \
  -exec bash -c "sips -g pixelHeight -g pixelWidth {} | grep -E ' [12]?[0-9]{0,2}$' >/dev/null" \; \
  -exec mv {} /path/to/some/other/folder \; 

Replace path/to/some/other/folder with the folder you want the files moved to, and that command will move the files it finds there.


The way this works is as follows:

The sips command is the scriptable image processing system. The terminal command sips -g pixelHeight -g pixelWidth some.jpg will print out the width and height of the JPEG file.

The find command, as one might expect, finds files. -exec passed to find tells find to execute the specified command and only return files for which the command returns a successful result.

The command bash -c "sips -g pixelHeight -g pixelWidth {} | grep -E ' [12]?[0-9]{0,2}$' invokes a shell, runs sips to get the image size, and then runs grep, which searches text, asking grep to search for either a 1 or a 2 followed by between zero and two digits (0 through 9). This is a regular expression, and it matches the numbers (strings) 1 through 299

share|improve this answer
add comment

In Aperture you can do this. And More!

Step 1

  1. Import all files into Aperture.
  2. Use list view.
  3. Click on an image size criteria to sort by that criteria. Note pixel dimension is probably the best method to use.

  4. Select all files below your minimum size.

  5. Delete

Now for step 2 assuming these are family photos.

  1. Turn on face recognition in Aperture, assign names to all recognizable faces.
  2. Wait until library has been processed.This may take a while depending on number of files.
  3. Now you can sort by face. (perhaps create a smart album for each face)
  4. Select all photos containing a particular face.
  5. Batch change metadata (shift + cmd + b), add a suitable keyword for each face.

Now you can export your files into suitable folders depending on who is in each folder. Plus a folder of files with no one in them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.