Split image

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
ahstanin
Posts: 1
Joined: 2017-01-02T23:34:43-07:00
Authentication code: 1151

Split image

Post by ahstanin »

Hello there magicians,

I need a magical spell for my work. I will have an uploader where people can upload random sized images. I want those to Split each image in random pieces depend on the image size. All Split-ed output has to be in square size (eg. 100X100 or 200X200). There will be always 3 Split by width and for hight depending on the image size. Some examples bellow :

1. User upload a random picture which is a square (2049 X 2049). It will be Split 3 pieces in width and 3 pieces in height because it's a square image. As I mentioned earlier Split-ed output has to be in square size. Each piece will be 683X683 and total 9 pieces.

Code: Select all

convert -crop 33.33%x33.33% +repage DSC_0972.jpg out%d_image.jpg
This CLI work perfect for me.

2. User upload a random picture which is a landscape (2049 X RANDOM_HEIGHT). It has to Split 3 pieces in width and XYZ pieces in height depending on the picture size. As well all Split-ed output has to be in square size.

3. User upload a random picture which is a portrait (2049 X RANDOM_HEIGHT). It has to Split 3 pieces in width and XYZ pieces in height depending on the picture size. As well all Split-ed output has to be in square size.


Note: Width always will be Split 3 pieces and final Split pieces has to be square (eg. 100X100 or 200X200).


Thank You in advance
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Split image

Post by snibgo »

ahstanin wrote:2. User upload a random picture which is a landscape (2049 X RANDOM_HEIGHT). It has to Split 3 pieces in width and XYZ pieces in height depending on the picture size. As well all Split-ed output has to be in square size.
So the width of each output square will be 2049/3 = 683 pixels. As they are square, the height of each will also be 683 pixels. This will work only when RANDOM_HEIGHT is an exact multiple of 683.
snibgo's IM pages: im.snibgo.com
Post Reply