title: How to split an image horizontally into equal-sized pieces?
body: <p>I am trying to split this input image into three/four equal-sized pieces horizontally but I am not getting the desired output. I don't know what I am doing wrong.
  Here is the code which I wrote to split it:</p>
  <pre class="lang-py prettyprint-override"><code>import os.path
  import numpy as np
  from PIL import image
  
  input_1 = &quot;/home/task-1/split_operation/111.jpg&quot;
  outputPath = &quot;/home/task-1/split_operation/&quot;
  im = Image.open(input_1)
  x_width, y_height = im.size
  split = np.int(x_width / 3)
  outputFileFormat = &quot;{0}-{1}.jpg&quot;
  baseName = &quot;cropped_1&quot;
  for i in range(0, x_width, split):
      x = split + i
      box = (x, 0, x + split, y_height)
      a = im.crop(box)
      a.load()
      outputName = os.path.join(outputPath, outputFileFormat.format(baseName, i + 1))
      a.save(outputName, &quot;JPEG&quot;)
  </code></pre>
  <p>The input image:</p>
  <p><a href="https://i.stack.imgur.com/mj4sd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mj4sd.jpg" alt="Itś an input image" /></a></p>
  <p>The output images I currently get:</p>
  <img src="https://i.stack.imgur.com/B3zSL.jpg" width="150">
  <img src="https://i.stack.imgur.com/IdFUL.jpg" width="150">
  <img src="https://i.stack.imgur.com/LKWz6.jpg" width="150">
  <img src="https://i.stack.imgur.com/PY0tM.jpg" width="150">
  <p>As you can see last two images are black. I don't know why I am getting a black image.</p>