0

I'm trying to copy an image and paste it to another one, and do it with all the images in a folder of 500 images.

When I run this code nothing happens.

I put an Image.show() to see what's happening, and when I run it the following error appears: "AttributeError: 'NoneType' object has no attribute 'show' "

from PIL import Image
import os 

f = r'C:\Users\Utente-XB\Desktop\img\imgResized\New folder' 
Layout_image = Image.open("Portada-blanco.jpg")
area = (120, 200, 470, 550)
for file in os.listdir(f): 
       f_img = f+"/"+file
       im = Image.open(f_img)
       im2 = imgFondo.paste(im, (120, 200, 470, 550))
       im2.show()
       im2.save(f_img)
V-cash
  • 330
  • 3
  • 14

1 Answers1

0

PIL's Image.paste() function accepts an image as its input, not a file path. Here's how it should be used in your code:

im = Image.open(f_img)
New_img = Layout_image.paste(im, area) 

Additionally, PIL's Image.save() function accepts a file path as its input, not an Image - you have to call .save() on the Image itself:

New_img.save(f_img) # Use the path f_img or whichever one you want
Random Davis
  • 6,662
  • 4
  • 14
  • 24