0

I receive a large number of images that are submitted by various people within our company. Rather than go through all of them manually, is there a way to have images that aren't at least 300dpi and 1800px in height/width be "rejected" into a separate folder?

Chenmunka
  • 3,228
  • 13
  • 29
  • 38
Seanaber
  • 1
  • 1

2 Answers2

2

There is nothing standard to do this with.
You need some kind of script that runs periodically through the folders(s) and moves the files that don't meet your criteria to a "rejected" folder.
Easiest is probably to script something with ImageMagick.
This is set of (free) command-line utilities for image-conversion and/or manipulation. There are commands in there to query the size/resolution and color-dept of images in many different image formats.
The "identify" command of ImageMagick will probably be most useful.

E.g:

$ identify rose.jpg
rose.jpg JPEG 640x480 sRGB 87kb 0.050u 0:01
Tonny
  • 29,601
  • 7
  • 52
  • 84
0

Tip:
ExifTool is available for windows, and will happily move about or copy files based on the metadata.

For what it is worth: "DPI" is only valid in relation to PRINTED or SCANNED images. The metadata values labelled "DPI" can be changed by use of Exiftool - and has no relevance what so ever for viewing files on a computer, nor the "quality" of the image at hand.

NOTE: Many older and probably also newer point and shoot cameras has 72 DPI as a default that cannot be changed in the camera

The fact that e.g. Photoshop displays images at a size dependent of this value is just "bull" - a lapse of mind from the developers. All you need to do is record an "Action" that sets the DPI-values to 300 or more (Resize image) - it runs in a fraction of a second and retains the image "as is"; just make sure to untick [v] Resample image. From then on PS will skip the "bull" to a reasonable level.


Example: Create a sortimages.bat file with this single line in it.
@exiftool  -jfif:Xresolution=300 -jfif:Yresolution=300 -r -d ..\SortedPictures\%Y\%Y-%m-%d_%%f.%%e "-filename<createdate" %1

Make sure to save it in a dir that is present in the PATH variable. Or add e.g. ;C:\cmd-utils\ to the end of PATH, create the dir, place the bat file in the dir.
Download Exiftool.exe and place it in the same dir.
As you have started cmd.exe running the bat file will be just a simple sortimages.

From then on
cd /d DIR_WHERE_YOUR_IMAGES_LIVE
followed by
sortimages *.*
will;

a) reset the resolution metadata to 300 DPI for all images,
b) copy the images into a folder named SortedPictures - one step up in the dir-tree (=parent dir, to avoid clashes with the current job).

Each image will be placed into a subfolder for year taken, and having a filename that reflects the date and time it was taken.

A slight warning: This isn't foolproof, e.g. images that do not have a creation date in the metadata will not be placed in the new dir; they will have the resolution values reset and get copied to the original filename, and the original file will remain in place with an additional "original" added appended to the name.

More to read:
https://raspberrypi.stackexchange.com/a/14359/17854
I want to change DPI with ImageMagick without changing the actual byte-size of the image data

Exiftool - http://www.sno.phy.queensu.ca/~phil/exiftool/


Now, the reject on the size might be a challenge for cmd.exe users (I see no easy solution).
I have no idea how well PowerShell handles the situation - I'd expect it to be "good" though:

exiftool -p '$Filename - $ImageSize' *.*
will print filenames and image sizes in a simple table.


Here is one extra; I'm not versed with cmd.exe nor Powershell in the same manner, sorry.

Autorejection, either in linux or www.cygwin.com using the bash shell

A single-line execution... (make sure all ; do NOT have leading spaces)

exiftool  -p '$Filename $ImageWidth $ImageHeight' *.jpg  | ( while read f w h; do if [ "$w" -gt "$h" ]; then t="$h"; h="$w"; w="$t"; fi; echo "$f $h"; if [ "$h" -lt "1800" ]; then mv "$f" "REJECTED_$f"; fi; done )

or as a short script²:

#!/bin/bash

exiftool  -p '$Filename $ImageWidth $ImageHeight' *.jpg  \
| ( 
  while read f w h; do
    if [ "$w" -gt "$h" ]; then
      t="$h"
      h="$w"
      w="$t"
    fi
    echo "$f $h"
    if [ "$h" -lt "1800" ]; then
      mv "$f" "REJECTED_$f"
    fi
  done )

² To create it; pick up notepad or nano and type it in, save as a file. Do chmod 755 filename and it will behave just as any executable.

Hannu
  • 8,740
  • 3
  • 21
  • 39
  • *Done* - the major *pickyness* issues removed. – Hannu Jul 10 '15 at 16:30
  • 1
    Didn't know ExifTool and just played around with it. $ImageWidth and $ImageHeight in the print example will split the width height in separate fields. If you use a format-file for -p containing a single line "$Filename $ImageWidht $ImageHeight" you can parse the output with the FOR command in cmd.exe to filter the sizes. – Tonny Jul 10 '15 at 19:18
  • Nice, I just spent some time trying to find those (ImageW/H) - couldn't lay my eyes on them for the example images - strange. FWIW: cmd.exe is strange, much of the "parsing" is hidden in strange places - I avoid it if I can. Install www.cygwin.com to get a "normal" shell. – Hannu Jul 10 '15 at 19:25
  • I just guessed the fieldnames, tried it and they worked :-) I must have written at least 10000 lines CMD script in my career, but I prefer a Unix-shell anytime. I used cygwin a lot in the past, but these days on Windows I prefer MobaXterm: a single executable with a shell, most cygwin commands, ssh client, X server, scp. It even can use my existing putty sessions. No need to setup a complete cygwin environment and it's portable: No need for local admin rights to use it. – Tonny Jul 13 '15 at 15:33