# Introduction to Gemini's Image Generation Request Parameters

Introduction to Gemini's Image Generation Request Parameters

Welcome to the second lesson of our course, "Creating Images with Gemini's Image Generation and Symfony." In this course, you will explore the fascinating world of AI-driven image generation using Google's Gemini API and its native image generation model. This lesson builds upon our previous lesson where we built the GeminiImageGenerator wrapper class. Now, we'll focus on using this wrapper to generate images with various configurations and parameters. We'll also explore Symfony, a powerful PHP web framework that will help us integrate and display our generated images.

Setting Up the Environment

Before we dive into generating images, it's crucial to set up our environment correctly. First, ensure you have PHP installed on your system (PHP 8.1 or higher is required for this setup). You'll need Composer, PHP's dependency manager, to install the required packages. On CodeSignal, many libraries come pre-installed; however, it's good practice to know how to install them on your own device.

For this lesson, we'll use Symfony's HTTP Client component to make API requests and handle environment variables. You can install these dependencies using Composer:

composer require symfony/http-client symfony/dotenv

If you're setting up a complete Symfony project, you can use:

composer create-project symfony/skeleton my-image-generator
cd my-image-generator
composer require symfony/http-client symfony/dotenv

Next, you should create a .env file in your project root to store your Gemini API key and base URL. The code in this course reads both values, so a local project must define each one:

GEMINI_API_KEY=your_api_key_here
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/

Make sure to add .env to your .gitignore file to prevent accidentally committing your API key to version control.

Using the GeminiImageGenerator Wrapper

With the environment set up, the next step is to use the GeminiImageGenerator wrapper we built in the first lesson. Let's load our environment variables and instantiate the wrapper:

<?php
// Load Symfony's autoloader
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/GeminiImageGenerator.php';

// Use Symfony's environment variables component to load .env
use Symfony\Component\Dotenv\Dotenv;

// Load environment variables from .env file if it exists
if (file_exists(__DIR__ . '/.env')) {
    (new Dotenv())->load(__DIR__ . '/.env');
}

// Create our image generator
$imageGenerator = new GeminiImageGenerator();
Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal