1

I have a lot of images of accommodations and restaurants for my webpage, but each images has different sizes. For example, I have one image of 300x250 and another one of 550x300.

I want to make squares cropping this images from 300x250 to 250x250 and 300x550 to 300x300 for example.

I find some command to crop images with "imagemagic" but I can't crop as square, centered.

I want to make a copy of all my images squared and then resize all to the same size.

I try with this command but I get "No such file or directory" error.

find . -name '*.jpg' -type f -exec bash -c 'convert -define jpeg:size=200x200 ${0%.jpg}  -thumbnail 100x100^ -gravity center -extent 100x100  $0_thumbnail.jpg'  {} \;

Now, I can crop images with this code:

find . -name '*.jpg' -type f -exec bash -c 'convert -define jpeg:size=200x200 $0  -thumbnail 100x100^ -gravity center -extent 100x100  ${0}_thumb.jpg'  {} \;

But cropped image gets this name "X.jpg_thumb.jpg". How can I modify this command to create X_thumb.jpg filename?

[SOLVED] This command solve my problem "%.*"

 find . -name '*.jpg' -type f -printf "%f\n" -exec bash -c 'convert -define jpeg:size=200x200 $0  -thumbnail 100x100^ -gravity center -extent 100x100  ${0%.*}_thumb.jpg'  {} \;
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Argoitz
  • 339
  • 1
  • 3
  • 15
  • 1
    See https://stackoverflow.com/a/53660350/2836621 – Mark Setchell Jan 15 '19 at 12:59
  • Thank you @MarkSetchell but how do I crop recursively all images and rename all to X_thumb.jpg? With this code,`find . -name '*.jpg' -type f -exec bash -c 'convert -define jpeg:size=200x200 $0 -thumbnail 100x100^ -gravity center -extent 100x100 $0' {} \;` I can modify all my image cropping as I want, but I don't know how to change the name to X_thumb.jpg – Argoitz Jan 15 '19 at 13:10
  • What is `X` please? – Mark Setchell Jan 15 '19 at 13:14
  • X is the original filename. Like "image.jpg" – Argoitz Jan 15 '19 at 13:16
  • 1
    Personally I would advocate using **GNU Parallel** as it splits paths, basenames and extensions simply, avoids quoting and escaping issues and is performant. – Mark Setchell Jan 15 '19 at 13:23
  • Ok I solve it with this code: ` find . -name '*.jpg' -type f -printf "%f\n" -exec bash -c 'convert -define jpeg:size=200x200 $0 -thumbnail 100x100^ -gravity center -extent 100x100 ${0%.*}_thumb.jpg' {} \; ` – Argoitz Jan 15 '19 at 13:30

1 Answers1

0

SOLUTION

find . -name '*.jpg' -type f -printf "%f\n" -exec bash -c 'convert -define jpeg:size=200x200 $0  -thumbnail 100x100^ -gravity center -extent 100x100  ${0%.*}_thumb.jpg'  {} \;
Argoitz
  • 339
  • 1
  • 3
  • 15