Search code examples
pythonphotoshopphotos

How to bulk add image strip programatically?


I have thousands of images. I want to bulk edit them to add a strip containing the Instagram, Facebook and Twitter account usernames at the bottom of the images.

Sample image is here : https://data.whicdn.com/images/254261469/large.jpg

Can the same strip be added programatically preferably using Python .


Solution

  • To give you something to start with. The sample below will paste an image into another image using the Pillow/PIL library. It paste a logo image at (25, 25) from the upper left corner of the original image and saves it.

    from PIL import Image
    
    # Load the image you want to modify
    image = Image.open('large.jpg')
    print("Image size is ", image.size)
    
    # Load the logo you want to paste in
    logo = Image.open('logo.png')
    # Decide what size you need possibly based on the first image?
    # Here we are just reducing the size so it has a higher chance to fit
    logo = logo.resize((logo.size[0] // 4, logo.size[1] // 4))
    
    # Paste the logo into the image
    image.paste(logo, (25, 25))
    
    # Save the new image
    image.save("test.jpg", format='jpeg')
    

    Additional things you need to know:

    • The image pasted in must be of the exact size as it appears in the original image. This is why i added the resize code.
    • If you are working with images of different sizes you probably need to find a working formula for how to place the new logos. Hopefully they have been added consistently to all images.
    • Make sure you read up on the Pillow docs (link below)
    • You could end up reducing the image quality when working with jpg images. See the docs for the save method.

    http://pillow.readthedocs.io/en/latest/reference/Image.html