ImageSequenceClip from moviepy library gives me Exception: ImageSequenceClip requires all images to be the same size

this is my function

def create_image_sequence(images, fps=None, aspectRatio=None, resolution=None):
    '''
    Takes request.FILE images and makes video sequence it finnaly transfers to gif
    
    DONT FORGET TO DELETE GIF
    '''
    
    #STORING IMAGES INTO TMP FOLDER
    imagesTMPpaths = []
    
    for key, value in images.items():
        ext = photo_extension(value)
        
        tmp_image = tempfile.NamedTemporaryFile(delete=False, suffix=ext)
        tmp_image.write(io.BytesIO(value.read()).read())
        tmp_image.close()
        
        imagesTMPpaths.append(tmp_image.name)
        print(f'{key}: {value}')
    

    #GETTING SMALLEST WIDTH --------
    
    images_sizes = []
    
    for image_tmp_path in imagesTMPpaths:
        
        with Image.open(image_tmp_path) as img:
            
            width, height = img.size #returns duplets
            images_sizes.append([width*height, width, height])
        
    images_sizes.sort() #it automaticly sorts by its first value
    print('xxxxxxxnSize resizing to: ', images_sizes[0], 'nxxxxxxx')
    
    #GETTING SMALLEST WIDTH end --------
    
    
    #RESIZE IMAGES TO SMALLEST ONE --------
    print('nresizing procesn-------')
    for image_tmp_path in imagesTMPpaths:
        #/a/4271003 (resize with black fillers/padding)
        
        with Image.open(image_tmp_path) as img:
            print('noriginal size: ', img.size)

            imgModified = ImageOps.pad(Image.open(image_tmp_path), (images_sizes[0][1], images_sizes[0][2]), color='black')
            
            imgModified.save(image_tmp_path)
            print('modified size: ', imgModified.size)
            print('PASSED: ', imgModified.size == (images_sizes[0][1], images_sizes[0][2]), 'n')
        
        
    # Verify all images have been resized correctly
    for image_tmp_path in imagesTMPpaths:
        with Image.open(image_tmp_path) as img:
            img = Image.open(image_tmp_path)
            print('size: ', img.size)
            print('PASSED: ', img.size == (images_sizes[0][1], images_sizes[0][2]), 'n')
        
    
    print(imagesTMPpaths)
    print(type(fps))
    print(f'fps: --{fps}--')
    print(fps not in [None,''])
    
    
        
    # Creating image sequence clip
    if fps in [0, None, '']:
        fps = len(imagesTMPpaths)
    else:
        fps = int(fps)
    
    imageSequence = ImageSequenceClip(imagesTMPpaths, fps=fps)
    
    
        
    if resolution  not in [None,'no change']:
        width, height = map(int, resolution.split('x')) #split will split around X and map makes two outputs int
        print('Resolution allowed:', resolution)
        print(width, height)
        imageSequence = imageSequence.resize(newsize=(width, height))
        print("Resolution updated. New size:", imageSequence.size)
    
    # Adjust aspect ratio if specified
    if aspectRatio not in [None,'no change']:
        print('Aspect ratio allowed:', aspectRatio)
        x, y = map(int, aspectRatio.split(':'))
        
        imageSequence = imageSequence.resize(newsize=(imageSequence.size[0], int(imageSequence.size[0] * y / x)))
        print("Aspect ratio updated. New size:", imageSequence.size)
    
    
    #final GIF
    tmp_gif = tempfile.NamedTemporaryFile(delete=False, suffix='.gif')
    
    
    imageSequence.write_gif(tmp_gif.name, program = 'ffmpeg')#WRITING INTO --> tmp_gif,  when using same tmp_gif path!
    imageSequence.close()
    
    tmp_gif.close()
    
    for image_tmp_path in imagesTMPpaths:
        os.remove(image_tmp_path)
    
    return tmp_gif.name

Everything works fine until it hits imageSequence = ImageSequenceClip(imagesTMPpaths, fps=fps)
even after i validate in console that images have same width and length it still makes the exception.

This is output from console:

####-web-1  | 0: xddd.png
####-web-1  | 1: Candlera-7_c582e094-1714-43df-bc18-a56e8277bd91.webp
####-web-1  | xxxxxxx
####-web-1  | Size resizing to:  (111, 194) 
####-web-1  | xxxxxxx
####-web-1  | 
####-web-1  | original size:  (111, 194)
####-web-1  | modified size:  (111, 194)
####-web-1  | PASSED:  True
####-web-1  |
####-web-1  |
####-web-1  | original size:  (700, 700)
####-web-1  | modified size:  (111, 194)
####-web-1  | PASSED:  True
####-web-1  |
####-web-1  | size:  (111, 194)
####-web-1  | PASSED:  True
####-web-1  |
####-web-1  | size:  (111, 194)
####-web-1  | PASSED:  True

then it hits the exception: ImageSequenceClip requires all images to be the same size

As you see in code i tried resizing images to smallest image size but with same ratio from original image so i used this this: imgModified = ImageOps.pad(Image.open(image_tmp_path), (images_sizes[0][1], images_sizes[0][2]), color='black')

and after that i validated twice in console if the sizes are correct and output from console is showing it is same.

I tried to wipe entire tmp folder in docker but it didnt help i tried rebuild entire container and it didnt help.

New contributor

Bruno Vontor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật