-1

I am using ImageIO to create a .gif file. I have 3 .png images with different sizes as:

(width, length, rgb)
(2520, 1800, 3)
(3840, 1800, 3)
(1800, 1800, 3)

As its visible that 2nd image is too wide and its going out of the frame. Is it possible to fix the frame size of the .gif so that it can accommodate the dimensions of all the three images?

Currently, its assigning 1st image's dimensions to the gif file.

Here is the code:

images = []
for filename in sorted(image_files):
    image = imageio.imread(filename)
    images.append(image)
imageio.mimsave('file.gif',images, duration=1)
Kush
  • 41
  • 3
  • Welcome to Stackoverflow! It is hard for us to suggest solutions without seeing what code you are working with! Please add your code to the question post, and be explicit about which part of the code you think needs to be changed. – Kevin Oct 24 '19 at 15:35

1 Answers1

1

To create gif from images of different sizes, we can use "moviepy.editor" and concatenate the images by passing argument method="compose".

method="compose" retains the dimension of each image(frame) and creates a gif file with the frame of maximum height and width.

Here is the code:

def make_gif():
        input_png_list = glob.glob(infile+'/*.png')
        input_png_list.sort()
        clips = [mpy.ImageClip(i).set_duration(self.duration)
                 for i in input_png_list]
        concat_clip = mpy.concatenate_videoclips(clips, method="compose")
        concat_clip.write_gif("test.gif", fps=2)
Kush
  • 41
  • 3