You could also use theimagemagick fx operator to filterallows filtering images based on height/width e.g.
(( $(identify -format '%[fx:(h>400 && w>400)]\n']' image.png) ))
the inner command will output 1 if the image is bigger than 400x400 and 0 if it's equal or smaller than 400x400...
Assuming sane files names (no newlines/spaces/tabs etc) you could use so the identify(( )) expression will evaluate to print image names preceded by either 1: or 0:, process the output deleting lines that start with 0:true and removing the leadingrespectively 1:false on the rest of lines so only. So you could iterate over the file names remain, one per linefiles and run this test, adding the positives to an array which is then pipe that listpassed to mogrify ... @- (the @ syntax was added in imagemagick v6.5.2)as arguments:
identify -format '%[fx:args=(h>400)
for &&f w>400)]:%i\n'in ./*.png | \
sed '/^1:/!d;//s///' | mogrify -resize '400x400' -- @-do
Otherwise, with find you could print only the files with size > 400x400 and then pipe the result to xargs + mogrify (it's less efficient as it runs a shell for each file but it should work with all kind of file names):
find . -maxdepth 1 -type f -name '*.png' -exec sh -c(( \
'identify$(identify -format "%[fx'%[fx:(h>400 && w>400)]\n" "$0" |]' grep"$f") -q)) 1'&& {args+=("$f"} \; -print0 \
| xargs -0 done
mogrify -resize '400x400' "$args[@]"
If you're a zsh user see also this answer.