PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to crop images in same dimension W/H (Ubuntu 16)

 July 27, 2022     command-line, crop, image, imagemagick, ubuntu-16.04     No comments   

Issue

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'  {} \;

Solution

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'  {} \;


Answered By - Argoitz
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing