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.
Code (Python)
import requests
def main():
response = requests.post(
"https://api.aimlapi.com/v1/images/generations",
headers={
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type": "application/json",
},
json={
"prompt": "slightly dim banner with abstract lines, base colors are coral, yellow and magenta",
"model": "flux/schnell",
"image_size": {
"width": 1536,
"height": 640
}
}
)
data = response.json()
print("Generation:", data)
if __name__ == "__main__":
main()Model response & Generated image preview
Generation: {'images': [{'url': 'https://cdn.aimlapi.com/eagle/files/kangaroo/k6KvRjgHGF98TanFAf89x.png', 'width': 1536, 'height': 640, 'content_type': 'image/jpeg'}], 'timings': {'inference': 0.4465899569913745}, 'seed': 2166405766, 'has_nsfw_concepts': [False], 'prompt': 'slightly dim banner with abstract lines, base colors are coral, yellow and magenta'}Image preview:

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.
Settings
Select the Crop video tab and enter the URL of your video.

Using the preset aspect ratios or manual settings, adjust the area of your video that you want to turn into a GIF banner. Then click Set, and after that — Crop video.

After a few seconds of processing, a window with the cropped video fragment will appear below. Right-click on it and select Save.

Convert to GIF
For this step, we used another free web service.
Settings
Click Choose Files and upload your cropped video. After that, the output GIF settings will become available. Set your desired width.

Scroll down in the settings to find the GIF compression parameter. We set it to minimum for better image quality, but for larger videos, feel free to experiment with different values. Then click Convert to GIF.

All that's left is to upload the finished GIF file. In the next section, you can see it in action.
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?

