Search code examples
imagemagickimagemagick-convert

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?


Solution

  • 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