Runoob Tutorial ArchiveEnglish

Introduction to AI Image Generation

Introduction to AI Image Generation

Previously, to create a promotional image for a website, you either had to find materials yourself, hire a designer, or endlessly browse stock image websites if all else failed.

But a common problem was encountered: even after finally finding a satisfactory image, the subject's position was incorrect.

For example, if we wanted to create a web banner for a cafe event, with the event title on the left and a cup of coffee displayed on the right, the coffee cup on the stock image website was stubbornly placed in the center, leaving no room for text.

Now, you can let AI generate images directly according to our requirements:Place the coffee on the right, leave white space on the left, use a warm-toned background, soft lighting, and even specify the image aspect ratio in advance.

This chapter will use this example to learn how to use AI image generation tools to create a cafe event banner truly suitable for a webpage, starting from a text description.

No need for Photoshop or drawing skills; as long as you can clearly describe the desired image, you can start.


I. What is AI Image Generation

AI Image Generation is creating new images based on text descriptions, reference images, and other inputs using artificial intelligence models.

The most common method is calledText-to-Image.

For example, input:

Example: The simplest image generation prompt

Generate an image of a latte in a cafe.

AI can generate a coffee-themed image based on the description.

However, this sentence does not specify where the coffee cup should be placed, what art style to use, what color the background should be, or the image aspect ratio.

Therefore, the generated image may be beautiful, but it may not meet the actual use case.

Three common AI image processing methods

Method Function Application scenario
Text-to-Image Generate brand new images based on text descriptions Website illustrations, event posters, illustrations
Image-to-Image Generate new scenes referencing an existing image Style transfer, product scene design
Image Editing Modify existing images according to requirements Replace background, adjust composition, remove objects

This lesson mainly studies the first type—text-to-image, and later demonstrates how to modify the generated results through multi-turn dialogue.

It should be noted that AI does not simply stitch images together based on a few keywords. The model creates scenes by combining the overall semantics of the prompt, visual relationships, and random factors during the generation process, so the same prompt may yield different results.


II. Writing good image prompts: First, master the six elements

In the previous chapter, "Introduction to AI Prompts," we learned how to clearly describe a task.

Image generation is the same, but what we describe is no longer the article structure, but the specific visual scene.

For beginners, you can first remember the six elements:

Subject + Scene + Lighting + Composition + Color Style + Aspect Ratio and Constraints

Element What needs to be explained This lesson example
** Subject The most important object in the picture A cup of steaming latte coffee
** Scene The location and environment where the subject is located Wooden desk, warm cafe
** Lighting Light direction, intensity, and atmosphere Soft morning sunlight by the window
** Composition Subject position, size, and negative space Cup on the right, negative space on the left
** Color style Overall color tone, illustration or photographic texture Warm brown, cream, natural photography style
** Aspect ratio and restrictions Aspect ratio and unnecessary elements 16:9, no text, Logo, watermark

For example, the two prompts below describe the same cup of coffee, but the generated targets are completely different.

Standard prompt Optimized prompt
Draw a cup of coffee A hot latte in a white ceramic cup, placed on the right side of a wooden table, with soft morning light streaming in from the window, leaving a large area of clean white space on the left, warm brown tones, 16:9 banner, no text

The second prompt clarified the most important composition requirements when using the webpage, making it easier to generate images that meet the requirements.

However, you do not need to write very long descriptions for every image just to complete six elements. Just make sure to clearly state the requirements that truly affect the result.


III. Practical Scenario: Creating a Cafe Web Banner

Assume we are designing an event page for a virtual cafe and need a horizontal background image.

The left side of the webpage will display the event title and buttons, and the right side will feature a cup of coffee to create a warm and relaxing atmosphere.

Since the text will be added separately through the webpage's HTML and CSS, no text should appear in the image.

First clarify the image requirements

Project Requirements
Use case Cafe event webpage banner
Image theme Warm cafe and latte coffee
Main subject Latte in a white ceramic mug
Aspect ratio 16:9
Composition Coffee on the right, white space on the left
Lighting Soft morning light
Color Creamy white, warm brown
Image style Simple and natural commercial photography
Constraints No text, logos, watermarks, or extra cups

The entire operation process is as follows:

The complete workflow of AI image generation from requirement description to webpage illustration

Why put the coffee cup on the right side

Because this image is not an illustration to be appreciated alone, but is to be placed on a webpage.

Our webpage title and activity buttons will be placed on the left. If the AI places the cup in the center of the screen, the text might overlap with the main subject later on.

Therefore,the final usage scenario should be considered when generating the image, not after generation when trying to adapt it.


Four, Step 1: Select an AI image generation tool

Currently, there are many AI tools that can generate images based on text, such as ChatGPT, Doubao, Qwen, which have image generation capabilities, and various professional image generation platforms.

For beginners, it is recommended to first choose a tool that can directly use natural language conversation.

Tool Types Features Suitable scenarios
Conversational image generation Directly describe requirements and modify through multi-turn conversation Web images, single illustrations, daily design
Professional image generation platform Provides more styles, parameters, and generation controls Series works, more complex visual designs
Local image generation tool Deploying models and workflows in a local environment Need custom models and local workflows

The supported image aspect ratios, editing capabilities, resolutions, and usage quotas may differ across platforms; check the tool's generation settings before use.

This lesson is not limited to any specific model; any model that supports generating images from text can be used for practice.


V. Step 2: Writing the first complete image prompt

Now we will create a cafe event banner.

We want to generate a horizontal commercial photography style image, showing coffee on the right and reserving a text area on the left.

Example: Generating a cafe webpage banner

Please generate a banner image for a cafe event webpage.

[Subject]

A hot latte in a white ceramic mug,

with natural coffee latte art on the surface,

with a small amount of gentle steam rising from the rim.

[Scene]

The latte is placed on a light wooden table,

with a warm, quiet cafe in the background.

[Lighting]

Morning sunlight softly shines into the room from the window side,

with natural light and shadow gradation.

[Composition]

16:9 horizontal frame.

The coffee cup is located on the right side of the frame,

the subject is complete and clear.

The left side, about 45% of the area, remains simple,

Used for placing titles and buttons on web pages.

[Color and Style]

Warm brown, cream, light wood color.

Natural commercial product photography texture,

Simple, warm, clean.

[Constraints]

Do not include any Chinese or English text.

No logos, brand marks, or watermarks.

Do not include a second coffee cup.

Do not include cluttered tableware or decorations.

Do not include people.

This prompt looks a bit long, but each part is actually very clear.

If the coffee cup in the generated result is too small, adjust the subject size; if the left side is not clean enough, strengthen the white space requirement; if the colors are too dark, modify the lighting description.

This is easier to control the results than rewriting the entire prompt every time.


VI. Step 3: Generate and check the image effect

After submitting the prompt to the AI tool that supports image generation, you can view the generated results.

Below are the actual example images for this chapter:

Example of an AI-generated cafe event webpage banner

After obtaining the image, do not rush to download and use it.

You need to judge whether it is qualified from the perspective of web design.

Image Checklist

Inspection Item Requirement
** Aspect Ratio Meets 16:9 banner requirements
Subject Only one latte, the cup body is intact
Negative space The left side is clean enough for text
Lighting Natural and soft, no abnormal highlights
Color palette Warm brown and cream colors are coordinated
** Details Rim, handle, and desktop perspective are natural
** Text No unexpected letters, garbled characters, or symbols should appear

What is easiest to overlook is white space.

Some images look beautiful on their own, but after putting them on a webpage, you realize the title is covering the coffee cup.

Therefore, it is recommended to simulate the position of the webpage text after generating the image before deciding whether to use it.


VII. Step 4: If the first generation is unsatisfactory, how to modify it

AI image generation rarely guarantees that the first result will perfectly match expectations.

Common issues include the cup being in the wrong position, the background being too complex, the lighting being too dim, or extra objects appearing.

At this time, you can directly request modifications in the same conversation.

Scenario 1: The coffee cup is placed in the center.

Example: Adjusting the image composition.

Please modify the previous cafe banner.

The current problem is:

The coffee cup is too close to the center of the frame.

Adjust the layout of the left webpage title.

Please adjust:

Move the coffee cup to the right side of the screen.

Keep about 45% of the left area as clean white space.

Keep the coffee cup intact.

Retain the original morning light and warm brown tones.

Maintain the original natural photography style.

Do not add new cups or other objects.

Do not add any text.

Maintain 16:9 aspect ratio.

Scenario two: Background is too cluttered.

Example: Simplify the image background.

Please continue to optimize the previous image.

Keep the appearance and position of the coffee cup unchanged.

Adjustments needed:

Reduce decorative items in the background.

Remove unnecessary tableware.

Simplify the left area.

Keep the background soft and natural.

Make the coffee cup the sole visual focus.

Do not change the image ratio.

Do not add text, logos, or watermarks.

Scenario three: The picture is too dark

Example: Adjust the image lighting

Please adjust the lighting of the previous image.

The overall image is currently too dark.

Modification requirements:

Increase the brightness of the morning natural light.

Retain the soft shadow layers.

Keep the background in cream and light brown colors.

Do not have overexposed windows.

Do not change the composition or quantity of the coffee cup.

Maintain a warm and natural cafe atmosphere overall.

If the tool supports editing based on the original image, try to keep the existing subject and only adjust the specified parts.

If the tool does not support precise local editing, it may regenerate the entire image, causing changes to the cup shape and background details.

Therefore, when creating a series of images, it is best to keep the satisfactory original image as a reference for subsequent editing.


VIII. Step Five: Controlling Image Size and Aspect Ratio

When generating images, you should consider the final usage size in addition to the content of the picture.

For example, the same cafe image requires different ratios for a website banner, product cover, and mobile poster.

Common image ratios

Aspect Ratio Common Pixel Sizes Applicable Scenarios
16:9 1920 × 1080 Web banners, presentations
1:1 1024 × 1024 Product images, social media graphics
4:5 1080 × 1350 Vertical poster, social media
9:16 1080 × 1920 Mobile portrait background, short video cover
2.35:1 1880 × 800 Ultra-wide web banner, article cover

Notes:16:9 is the aspect ratio, it does not mean the image must be 1920 × 1080 pixels.

Some models can only output a fixed set of sizes directly. If you require a strict pixel size, you can first generate the corresponding aspect ratio and then use an image tool to scale, crop, or pad it.

Have AI generate different size versions

For example, we want to use the same cup of coffee for both a web banner and social media.

Example: Generate three aspect ratios for the same theme

Please design three images for different uses based on the same cup of latte coffee.

The following visual theme must be maintained:

White ceramic cup

Natural coffee latte art

Light wooden tabletop

Soft morning light

Warm brown and cream color scheme

Warm brown and cream color scheme

A. Web banner

Aspect ratio: 16:9

Coffee cup on the right.

Keep clean white space on the left.

B. Product display image

Aspect ratio: 1:1

Coffee cup centered.

Highlight the cup and latte art details.

C. Activity poster background image

Ratio: 4:5

The coffee cup is placed in the lower half of the image.

A large area of white space is reserved at the top.

Common restrictions:

No text should appear.

No Logo should appear.

No watermark should appear.

Do not appear extra cups.

Try to keep the appearance of the cups consistent.

Please generate three separate images.

The main appearance between different images does not necessarily have to be perfectly identical like a copy-paste. If you have strict requirements for the product appearance, it is recommended to use real product images or edit using the same reference image.


Nine, Step Six: Use the generated images on the webpage

After the image generation is successful, the next step is to put it on the webpage.

Here is a very practical tip:Have the AI only generate background images without text; use HTML and CSS to add the webpage title and buttons.

There are several advantages to doing this:

Web banner HTML example

Assuming we have saved the generated image ascoffee-banner.webp, you can create a simple webpage banner using HTML and CSS.

Example: Add AI-generated images to a webpage

   

       

Coffee Time

       

Enjoy the warmth of a cup of coffee

       

Understand the event

   

This usesbackground-size: coverto make the image fill the banner area.

However, this also means the image may be cropped at different screen widths. Therefore, before the official launch, you need to check the mobile view to confirm that the coffee cup is not cut off and the text does not block the main subject.

If the composition on mobile is not suitable, you can generate another portrait or mobile-specific background image.


X. Seventh Step: Convert the image to WebP to optimize web loading

AI-generated images may be in PNG, JPG, or other formats.

If you plan to put it on a website, you also need to consider the file size.

For example, a 1920 × 1080 PNG image might have a file size of several MB. If used directly as a webpage banner, it may affect page loading speed.

For cafe photography images without a transparent background, you can consider converting them to WebP or other compressed formats suitable for the web.

Comparison of Common Image Formats

Format Characteristics Applicable Scenarios
PNG Supports lossless compression and transparent background Icons, transparent materials, and images that require precise detail retention
JPG Suitable for photos, wide compatibility Photography images, general webpage illustrations
WebP Supports lossy and lossless compression, and also supports transparent background Web banners, article illustrations, product images
AVIF Good compression efficiency, but encoding and compatibility need attention. Web images that need further optimization in size.

There is no single best quality parameter for image compression; it needs to be decided based on image details and actual display effect.

In this lesson, you can first convert the image to WebP and then compare the image quality and file size.

Use online image conversion tools.

If you are not familiar with image format conversion, you can use online tools to complete the conversion, and then check if the exported file is clear and if the aspect ratio is maintained.

After conversion, it is recommended to keep a high-quality original image for subsequent cropping or creation of other sizes.

Let AI help you formulate export requirements

Example: Web image export requirements

Please help me optimize the generated cafe banner image,

for formal web display.

Requirements:

Maintain the original 16:9 aspect ratio.

The target size is 1920 × 1080 pixels.

If scaling is necessary, do not stretch or distort.

Prioritize exporting as WebP.

Try to minimize the file size.

Maintain the clarity of the coffee cup and background.

Do not add text, logos, or watermarks.

Keep one original high-quality image.

If direct file conversion is not possible,

please specify the conversion method that can be used.

Check the final width, height, and file size after completion.

For web banners, the final image size should be determined by considering the actual display width and device pixel density, and it is not necessarily better the larger it is.


XI. Complete Example: Creating a Web Banner with a Prompt

Previously, we completed visual requirements, image generation, composition adjustment, and web export separately.

If you are already familiar with the operation, you can also use the complete prompt below.

Example: Complete Prompt for AI Cafe Banner

You are an e-commerce and web visual designer.

Please generate a web banner for a cafe promotion.

I. Use Cases

The homepage for the cafe activity.

A title and buttons will be added to the left side of the webpage,

so the image itself does not need to contain text.

II. Image Subject

A latte in a white ceramic cup.

Requirements:

The cup shape should be natural.

The coffee latte art should be clear.

There is a small amount of gentle steam on the surface.

Only one coffee cup appears.

III. Scene Environment

A warm, quiet cafe interior.

The tabletop is made of light-colored wood.

The background can have soft spatial layers,

but no cluttered decorations.

IV. Lighting

Natural sunlight in the early morning.

Soft and warm lighting.

Maintain realistic shadows and textures.

V. Composition

16:9 horizontal aspect ratio.

The coffee cup is located on the right side of the frame,

The main subject is complete and clear.

Approximately 45% of the left side area remains a simple white space,

Convenient for later overlaying web titles and buttons.

Do not let the cup be close to the edge of the screen,

to avoid being cropped on different screens.

VI. Color and Style

Warm brown

Cream

Light wood color

Natural commercial photography style

Simple, warm, and premium

VII. Constraints

Do not appear:

Chinese characters

English characters

Logo

Watermark

Second coffee cup

Characters

Cluttered tableware

Excess decorative elements

VIII. Output Requirements

Prioritize generating 16:9 images.

Suitable for web banners.

Clear subject, clean background.

Overall composition leaves space for text on the left side.

Please generate the image directly,

and do not add any descriptive text in the image.

This prompt can serve as a base template for creating other web images later.

For example, by replacing the coffee cup with headphones, a laptop, or a book, and then adjusting the scene and colors, you can generate banners with different themes.


Twelve. Frequently Asked Questions and Solutions

Problem Possible Cause Solution
Garbled characters appear in the image The model generated unnecessary identifiers or text Explicitly request no text background, remove locally if necessary
The coffee cup position is incorrect The main subject composition description is not clear enough Specify the right side position and the left white space ratio
The image is too crowded The scene contains too many objects Simplify the environment and limit the number of subjects
Coffee cup deformation Generated details have structural problems Regenerate or use local editing to correct
Dimensions do not meet requirements The model only supports specific generation sizes Scale or crop after generating the appropriate aspect ratio
Subject is cropped on the mobile end Desktop and mobile compositions are inconsistent Adjust the background position or use mobile-specific images
Image file is too large Original image has not been optimized for the web Adjust the size appropriately and convert to WebP
Inconsistent style across a series of images Visual features change with each regeneration Use unified prompts and reference images for editing

General image modification prompts

If the first generated image does not meet the requirements, you can use the template below to modify it.

Example: Modify an existing image

Please modify the image I provided.

Current issues:

[Fill in the content to be modified]

This time only needs to adjust:

[Fill in specific modification requirements]

Please try to retain the following parts:

The original main appearance.

The overall color style.

The aspect ratio of the image.

Background elements that are already satisfactory.

Other content that does not need modification.

Do not add new subjects.

Do not add text, logos, or watermarks.

If precise local modification is not possible,

please try to maintain visual features consistent with the original image.

Similar to modifying text, image editing should aim to solve one main issue at a time, avoiding redesigning the entire scene every time.


Thirteen, what to pay attention to when using AI-generated images for commercial promotion

AI-generated images can be used in many creative scenarios, but if you plan to put them on public websites, product pages, or in advertisements, further checks are required.

Check items Notes
** Use authorization Verify the platform's current terms of service and applicable laws
** Brand Identification Check for unauthorized brands or trademarks
** Portrait of Individuals Confirm permissions when using real people's images or reference photos
** Visual Accuracy Check product form, text, and important details
** Promotional Authenticity Avoid presenting fictional scenes as real products or services.

The cafe and latte used in this lesson are simulated scenes and do not use real trademarks or specific brands.

If used for promotion of a real cafe, be careful not to let consumers mistakenly believe that the generated photos of coffee cups, food, or environments are the actual products or store scenes offered.

Furthermore, the commercial use terms of different AI image platforms may vary. Even if the platform allows commercial use, it does not mean that the generated content automatically has exclusive copyright protection.


Fourteen, Hands-on Practice

Exercise One: Change the coffee banner to a library theme

Using the six-element prompt structure from this lesson, generate a 16:9 web banner with a library reading theme.

Requirements:

Exercise Two: Generate a square product image

Use the coffee cup from this lesson as the main subject to regenerate a 1:1 product image.

The coffee cup must be centered, highlighting the cup and coffee latte art details, with no need for web text or white space.

Exercise Three: Generating Mobile Banner

Change the original cafe webpage banner to an image suitable for mobile display.

You can try a 4:5 or 9:16 ratio, adjust the main subject's position, and leave space for text at the top.

Exercise Four: Optimizing Image Size

Convert the generated cafe banner to WebP and compare the file size and clarity before and after conversion.

Check for obvious compression blur, color changes, or loss of detail.