Create a Looped GIF for a Web Banner
Idea and Step-by-Step Plan
In this use case, we create an animated banner by combining image generation, video animation, and basic editing. Here’s the plan:
Generating a Reference Image We are going to use one of our image models to create a picture based on a prompt (which is our business idea).
Animating the Image We will pass the generated image to a video model that creates a smooth, perfectly looped animation.
Adjusting the Video Size We will use a free online service to crop the video to the desired banner dimensions.
Convert to GIF We will transform the final video into a GIF format for easy integration into websites.
Full Walkthrough
Generating a Reference Image
We chose a very fast image model flux/schnell, provided a prompt for an abstract image ("slightly dim banner with abstract lines, base colors are coral, yellow, and magenta"), and specified dimensions as close as possible to the sizes we needed for the website.
Unfortunately, it's not always possible to simply set the exact dimensions we need due to model limitations. For example, most image models require that both height and width values be multiples of 32. Video models may have minimum and maximum input size restrictions, and sometimes specific requirements for the aspect ratio as well.
Animating the Image
Not all video models are capable of creating looped videos (where the last frame matches the first one). We chose model kling-video/v1.6/pro/image-to-video. It accepts the first and last frames separately, using the parameters image_url
and tail_image_url
respectively.
For the video generation prompt, we used "slow fluid-like motion of patterns of the image." Feel free to experiment with effects, as long as they match the video looping!
Don't worry: the code below is long because it automates the process of requesting the ready video from the server every 10 seconds, so you don't have to do it manually. Enter your AIMLAPI key in the second line, and all the necessary parameters are passed in the first function, generate_video()
.
Adjusting the Video Size
For video cropping, we used the free web service.
Convert to GIF
For this step, we used another free web service.
Results
You can use such banners in the website header or overlay your promotional text on a transparent background in a website builder to make it look like a single element. Best of luck with your implementation!
Last updated
Was this helpful?