hello my programr must cut an image in 3 then recreates it by mixing the 3. But I have a problem that appears.thanks
"attributeError:‘str’ object has no attribute ‘size’
from PIL import Image
image1 = Image.open(".\christmas.png")
L, H = image1.size
image2 = Image.new(“RGB”,(L,H))
for y in range(H):
for x in range(L):
pixel = image1.getpixel((x,y))
r = pixel[0]
v = pixel[1]
b = pixel[2]
g = int( ®)
h = int( ®)
i = int( (v))
image2.putpixel((x,y),(g,h,i))
Partie 1
im_size = image2.size
# on défini la taille de notre première image (area1)
left = 0
top = 0
width = 539
height =179
box = (left, top, left+width, top+height)
on recadre notre image
area1= image2.crop(box)
area1.show()
#image 2
im_size = image2.size
left2 = 0
top2 =179
width2 = 539
height2 =179
box2 = (left2, top2, left2+width2, top2+height2)
area2 =image2.crop(box2)
area2 = area2.rotate(180)
area2.show()
#image 3
im_size = image2.size
left3 = 0
top3 = 358
width3 = 539
height3 =179
box3 = (left3, top3, left3 + width3, top3 + height3)
area3 = image2.crop(box3)
area3.show()
for b in range(L):
for c in range(H):
if 0<y<H/3 :
area1.putpixel((x,y),(g,h,i))
if H/3<y<(2H)/3 :
area2.putpixel((x,y),(i,i,g))
if (2H)<y<H :
area3.putpixel((x,y),(g,g,i))
area4= ‘area1’+‘area2’+‘area3’
area4.size=image1.size
area4.show()