AI Image

import com.google.genai.Client; import com.google.genai.types.Content; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.ImageConfig; import com.google.genai.types.Part; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class GroupPhoto { public static void main(String[] args) throws IOException { try (Client client = new Client()) { GenerateContentConfig config = GenerateContentConfig.builder() .responseModalities("TEXT", "IMAGE") .imageConfig(ImageConfig.builder() .aspectRatio("5:4") .imageSize("2K") .build()) .build(); GenerateContentResponse response = client.models.generateContent( "gemini-3-pro-image-preview", Content.fromParts( Part.fromText("An office group photo of these people, they are making funny faces."), Part.fromBytes(Files.readAllBytes(Path.of("person1.png")), "image/png"), Part.fromBytes(Files.readAllBytes(Path.of("person2.png")), "image/png"), Part.fromBytes(Files.readAllBytes(Path.of("person3.png")), "image/png"), Part.fromBytes(Files.readAllBytes(Path.of("person4.png")), "image/png"), Part.fromBytes(Files.readAllBytes(Path.of("person5.png")), "image/png") ), config); for (Part part : response.parts()) { if (part.text().isPresent()) { System.out.println(part.text().get()); } else if (part.inlineData().isPresent()) { var blob = part.inlineData().get(); if (blob.data().isPresent()) { Files.write(Paths.get("office.png"), blob.data().get()); } } } } } }

Comments