user3236841
user3236841

Reputation: 1258

split image horizontally into two unequal parts?

I have the following image:

enter image description here

I would like to use ImageMagick to split it horizontally into two unequal parts of 40-60% (L-R). How do I do this?

Upvotes: 1

Views: 853

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 208052

Just for fun, a slightly different version:

  • load image
  • make clone, crop left side and save, delete clone
  • revert to original, crop right side and save

magick GhLiu.png +repage \( +clone -crop 40x100%+0+0 +repage +write left.png +delete \) -gravity east -crop 60x100%+0+0 +repage right.png

Upvotes: 1

fmw42
fmw42

Reputation: 53202

You can do that as follows in ImageMagick 6. Read the image into MPR memory and delete the original. Then use the MPR copy to crop 40% once with gravity west and crop 60% again with gravity east (that is 40% from the left side and then 60% from the right side). Write those images and then exit with no output, i.e., null:

Unix Syntax:

convert red_rect.png +repage -write mpr:img +delete \
\( mpr:img -gravity west -crop 40x100%+0+0 +repage +write left.png \) \
\( mpr:img -gravity east -crop 60x100%+0+0 +repage +write right.png \) \
null:

For Windows,

convert red_rect.png +repage -write mpr:img +delete ^
( mpr:img -gravity west -crop 40x100%+0+0 +repage +write left.png ) ^
( mpr:img -gravity east -crop 60x100%+0+0 +repage +write right.png ) ^
null:

(In .bat file, double the % to %%)

(For ImageMagick 7, change convert to magick)

Left:

enter image description here

Right:

enter image description here

Upvotes: 2

Related Questions