top of page
  • Writer's pictureGabriele Sirtori

1:1 image splitter and grid maker for Instagram Carousels using a python script.

Updated: Jul 28

Seamless Instagram Carousel posts are cool and - according to some data - have the highest engagement rate among the different kinds of posts that you can publish.


I do it often on the Instagram page of Colnago.

See this example:


How? I create a carousel on Canva, in the form of a picture with a ratio of 3:1, 4:1, 5:1 or even (once) 7:1 and then I cut it into square.


How do I cut it into perfect 1:1 squares?


There are many methods, and most of them take a lot of time / involve risks.

So I made my own python script that you can find in the paragraph below.



Existing methods

You can create carousels and split images

  1. By using an online tool such Grid Maker by MySocialBoutique.co

  2. By using Canva itself

  3. By cutting it with apps such as those by Adobe (Illustrator or Photoshop)


They are all nice, except that

  1. Using an external website you have limits in the picture dimension, plus the resulting image is compressed/loses quality

  2. Using Canva is nice but it often leads to mistakes

  3. Using Adobe programs is the most professional solution, but... do you have access to them in the first place? They're so expensive!


To solve this, I created the following script, that uses standard python libraries.



My python script to split images and create Instagram carousels

Here it is:


#Add the image path
image_url = "C:/User/Desktop/pic_name.png"

#Import the "Image" Library from the PIL package
from PIL import Image

#Open the image and get its size
pic = Image.open(image_url)
h = pic.size[1]
w = pic.size[0]

#Crop it into as many squares as they fit
i = 0
while i < w//h:
    w0 = h*i
    w1 = h*(1+i)
    box = (w0, 0, w1, h)
    region = pic.crop(box)
    
    #Save the files such as this: "image_name_crop_1.png"
    file_name = image_url.split("/")[-1].split(".")[0]+"_crop_"+str(i+1)+".png"
    
    region.save(file_name)
    i += 1
    
print("done!")

The images are then saved in the same folder in which you are running your python script.


Share it if you found it helpful :)


Gabriele




142 views0 comments

Commentaires


Post: Blog2 Post
bottom of page