I need to convert a very large number of images JPEGs. those images some are 720px × 480px, and some 300x400 and some 2000x1400 and some are 1000x1000 etc.. I only need to resize those images to 1000x1000 without touch the images that have 1000x1000

here i try to make small script which is calculate the total size of each image w x h but i need to add if statement on it which is convert all images to 1000x1000 and exclude images that have 1000x1000 size

for image in *.jpg; do
read w h < <(identify "$image" | grep -oP '\d+x\d+(?=\+)')  
echo $((w*h)) "$image"

1 Answer 1


You could use the fx operator to filter images based on height & width e.g.

identify -format '%[fx:(h=1000 && w=1000)]\n' image.jpg

will output 1 if the image is exactly 1000x1000 and 0 otherwise.
So you could run something like this (adjust the convert command as per your needs):

for image in ./*.jpg; do
identify -format '%[fx:(h=1000 && w=1000)]\n' "$image" | grep -q 0 \
&& convert -resize 1000x1000 "$image" "${image%.*}"-converted.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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