Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
Imagen.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2026 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j;
10
11import io.github.ollama4j.exceptions.OllamaException;
12import io.github.ollama4j.models.generate.OllamaGenerateImageRequest;
13import io.github.ollama4j.models.response.OllamaImageResult;
14import java.io.IOException;
15import java.nio.file.Files;
16import java.nio.file.Path;
17import java.nio.file.Paths;
18import java.nio.file.StandardOpenOption;
19import java.util.Base64;
20
21public class Imagen {
22 public static void main(String[] args) throws OllamaException, IOException {
23 Ollama ollama = new Ollama("http://localhost:11434");
25 request.setModel("x/z-image-turbo");
26 request.setPrompt(
27 "A white boat with brown cushions, where a dog is sitting on the back of the boat."
28 + " The dog seems to be enjoying its time outdoors, perhaps on a lake.");
29 request.setWidth(512);
30 request.setHeight(512);
31 OllamaImageResult result = ollama.generateImage(request);
32 Path outputPath = Paths.get("/Users/amith.koujalgi/Desktop/result.png");
33 byte[] imageBytes = Base64.getDecoder().decode(result.getImage());
34 Files.write(outputPath, imageBytes, StandardOpenOption.CREATE);
35 }
36}
static void main(String[] args)
Definition Imagen.java:22
OllamaImageResult generateImage(OllamaGenerateImageRequest request)
Definition Ollama.java:949