Special crop and resize

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mattalexx

Special crop and resize

Post by mattalexx »

I wrote down what I need to accomplish and scanned it in:

Image

So I would provide width of the square (25) and the command would take care of the rest.

It would be cool if I could do the whole thing in one command. Is that possible?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Special crop and resize

Post by Bonzo »

How are you going to know what the shortest side is ?

Code: Select all

convert input.jpg -gravity center -crop 25x25+0+0 output.jpg
mattalexx

Re: Special crop and resize

Post by mattalexx »

Bonzo wrote:How are you going to know what the shortest side is ?
I was hoping the command would figure it out.
Bonzo wrote:

Code: Select all

convert input.jpg -gravity center -crop 25x25+0+0 output.jpg
This is cropping which is cool, but I need the image to be resized also so that the shortest side is 25 pixels,
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Special crop and resize

Post by Bonzo »

What does this give you?

Code: Select all

convert output.jpg -resize 25x25^ -gravity center -crop 25x25+0+0 result.jpg
See http://www.imagemagick.org/script/comma ... p#geometry
mattalexx

Re: Special crop and resize

Post by mattalexx »

Bonzo wrote:What does this give you?

Code: Select all

convert output.jpg -resize 25x25^ -gravity center -crop 25x25+0+0 result.jpg
See http://www.imagemagick.org/script/comma ... p#geometry

Code: Select all

convert: invalid argument for option `25x25^': -resize.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Special crop and resize

Post by Bonzo »

How are you running the code - command line, php etc.
mattalexx

Re: Special crop and resize

Post by mattalexx »

Bonzo wrote:How are you running the code - command line, php etc.
Linux command line, yes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Special crop and resize

Post by fmw42 »

convert input.jpg -resize '25x25^' -gravity center -crop 25x25+0+0 +repage result.jpg

but need IM v6.3.8-3 or higher
mattalexx

Re: Special crop and resize

Post by mattalexx »

fmw42 wrote:convert input.jpg -resize '25x25^' -gravity center -crop 25x25+0+0 +repage result.jpg

but need IM v6.3.8-3 or higher

Code: Select all

mattserver ~: convert --version
Version: ImageMagick 6.3.7 02/19/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC

mattserver ~: convert image.jpg -resize '25x25^' -gravity center -crop 25x25+0+0 +repage result.jpg
convert: invalid argument for option `25x25^': -resize.
mattserver ~:
Damn -- one point off! I wish there were some way to upgrade IM on my client's production server. But alas, there is not.

Am I SOL?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Special crop and resize

Post by fmw42 »

Damn -- one point off! I wish there were some way to upgrade IM on my client's production server. But alas, there is not.

Am I SOL?
Not completely out of luck. You can script it easy enough. I already have one called squareup at http://www.fmwconcepts.com/imagemagick/index.html.

I wrote the script before the ^ notation was available for -resize.
mattalexx

Re: Special crop and resize

Post by mattalexx »

fmw42 wrote:
Damn -- one point off! I wish there were some way to upgrade IM on my client's production server. But alas, there is not.

Am I SOL?
Not completely out of luck. You can script it easy enough. I already have one called squareup at http://www.fmwconcepts.com/imagemagick/index.html.

I wrote the script before the ^ notation was available for -resize.
That looks great! Thank you.
mattalexx

Re: Special crop and resize

Post by mattalexx »

fmw42 wrote:Not completely out of luck. You can script it easy enough. I already have one called squareup at http://www.fmwconcepts.com/imagemagick/index.html.
Hey I just tried it and it works exactly right. Thanks again!
Post Reply