Split in Half if width > height

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
OneSimpleQuestion
Posts: 3
Joined: 2020-02-13T07:42:18-07:00
Authentication code: 1152

Split in Half if width > height

Post by OneSimpleQuestion »

LINUX Version: ImageMagick 6.9.10-23 Q16 i686 20190101 (But I want to make it work under windows too)

I saw in another thread that you can rotate depending on width and height https://stackoverflow.com/questions/184 ... cal-images is there anything like that for cropping pictures? (use case: two pages scanned as a single image), if not, is there any single line option? Thanks

User avatar
fmw42
Posts: 26086
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split in Half if width > height

Post by fmw42 »

If you want to split in half if width > height, you can do that either with IM 6 and a lines of code to determine if width > height and a conditional and then -crop. Or you can do that in one command using IM 7 with inline computations for the conditional test.

See http://www.fmwconcepts.com/imagemagick/ ... .php#crop1

For IM7, you can do

magick input -crop "%[fx:w>h?50:100]x%[fx:w>h?100:50]%" output

OneSimpleQuestion
Posts: 3
Joined: 2020-02-13T07:42:18-07:00
Authentication code: 1152

Re: Split in Half if width > height

Post by OneSimpleQuestion »

Don't know if this is enough to show what I mean.

Image

Image

User avatar
fmw42
Posts: 26086
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Split in Half if width > height

Post by fmw42 »

In IM 7 you can do that as:

Code: Select all

magick input -crop "%[fx:w>h?50:100]x100%" output
For IM 6, you will need to script it.

OneSimpleQuestion
Posts: 3
Joined: 2020-02-13T07:42:18-07:00
Authentication code: 1152

Re: Split in Half if width > height

Post by OneSimpleQuestion »

Ok thanks. You acted like a good friend.

Post Reply