[GH-ISSUE #14581] flux2-klein Image Edit (Img2Img) ignores source image in ollama-js v0.17.5 #55967

Closed
opened 2026-04-29 10:04:56 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @larria on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14581

What is the issue?

The image edit (img2img) functionality of the ollama-js API has stopped working correctly in version 0.17.5. Previously (with older versions of ollama-js), flux2-klein model could accurately understand the original image and apply the requested modifications as per the prompt. However, in v0.17.5, the model appears to completely ignore the source image and generates content unrelated to the original image (instead of modifying it).

JS code for test as bellow:

import ollama from 'ollama';
import fs from 'fs';
import path from 'path';

// ================= Configuration =================
// Model used (recommended: x/flux2-klein or z-image-turbo)
const MODEL = 'x/flux2-klein';

// Input image path (ensure file exists)
const INPUT_IMAGE = './test.jpg'; 

// Output image path
const OUTPUT_FILENAME = 'output_bw.png';

// Prompt: Modify the fox in the original image to 3D cartoon style
const PROMPT = "Make it 3D cartoon style, and the fox one eye open, one eye closed, smooth 3D rendering, cute vivid style, high detail, soft lighting";

// ==================================================

async function runImg2ImgSingle() {
    console.log(`🚀 Starting img2img task`);
    console.log(`🤖 Model: ${MODEL}`);
    console.log(`📝 Prompt: ${PROMPT}`);

    // 1. Check and read source image
    if (!fs.existsSync(INPUT_IMAGE)) {
        console.error(`\n❌ Error: Input image '${INPUT_IMAGE}' not found`);
        console.error(`👉 Please place an image named '${INPUT_IMAGE}' in the current directory.`);
        return;
    }

    let sourceImageBase64;
    try {
        console.log(`📂 Reading image: ${INPUT_IMAGE}`);
        const fileData = fs.readFileSync(INPUT_IMAGE);
        sourceImageBase64 = Buffer.from(fileData).toString('base64');
    } catch (e) {
        console.error(`❌ Image read failed: ${e.message}`);
        return;
    }

    const startTime = Date.now();
    let resultImageBase64 = null;

    console.log(`\n---------------------------------------------------------`);
    console.log(`⏳ Requesting Ollama API (this may take a few seconds to minutes)...`);

    try {
        // 2. Call Ollama API (enable stream: true to show progress)
        const response = await ollama.generate({
            model: MODEL,
            prompt: PROMPT,
            images: [sourceImageBase64], // 【Key】Pass source image as Base64
            stream: true
        });

        // 3. Process streaming response
        for await (const part of response) {
            // Print progress bar
            if (part.completed && part.total) {
                const percent = Math.round((part.completed / part.total) * 100);
                process.stdout.write(`\r🚧 Generation progress: ${percent}% [${'#'.repeat(Math.floor(percent/5))}${' '.repeat(20 - Math.floor(percent/5))}]`);
            }

            // Capture generated image data (last response contains 'image' field)
            if (part.image) {
                resultImageBase64 = part.image;
            }
        }
        
        process.stdout.write('\n'); // New line

        // 4. Save result
        if (resultImageBase64) {
            const duration = ((Date.now() - startTime) / 1000).toFixed(2);
            const buffer = Buffer.from(resultImageBase64, 'base64');
            
            fs.writeFileSync(OUTPUT_FILENAME, buffer);
            console.log(`\n✅ Success! Image saved as: ${OUTPUT_FILENAME}`);
            console.log(`⏱️ Duration: ${duration} seconds`);
        } else {
            console.error(`\n⚠️  Stream ended but no 'image' data found in response. Check if the model supports image generation.`);
        }

    } catch (error) {
        console.error(`\n❌ API call error:`, error.message);
    }
}

runImg2ImgSingle();

original image for test
original image for test

Result in v0.16.1
Image

Result in v0.17.5
Image

Relevant log output


OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.17.5

Originally created by @larria on GitHub (Mar 3, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14581 ### What is the issue? The image edit (img2img) functionality of the ollama-js API has stopped working correctly in version 0.17.5. Previously (with older versions of ollama-js), flux2-klein model could accurately understand the original image and apply the requested modifications as per the prompt. However, in v0.17.5, the model appears to **completely ignore the source image** and generates content unrelated to the original image (instead of modifying it). JS code for test as bellow: ```javascript import ollama from 'ollama'; import fs from 'fs'; import path from 'path'; // ================= Configuration ================= // Model used (recommended: x/flux2-klein or z-image-turbo) const MODEL = 'x/flux2-klein'; // Input image path (ensure file exists) const INPUT_IMAGE = './test.jpg'; // Output image path const OUTPUT_FILENAME = 'output_bw.png'; // Prompt: Modify the fox in the original image to 3D cartoon style const PROMPT = "Make it 3D cartoon style, and the fox one eye open, one eye closed, smooth 3D rendering, cute vivid style, high detail, soft lighting"; // ================================================== async function runImg2ImgSingle() { console.log(`🚀 Starting img2img task`); console.log(`🤖 Model: ${MODEL}`); console.log(`📝 Prompt: ${PROMPT}`); // 1. Check and read source image if (!fs.existsSync(INPUT_IMAGE)) { console.error(`\n❌ Error: Input image '${INPUT_IMAGE}' not found`); console.error(`👉 Please place an image named '${INPUT_IMAGE}' in the current directory.`); return; } let sourceImageBase64; try { console.log(`📂 Reading image: ${INPUT_IMAGE}`); const fileData = fs.readFileSync(INPUT_IMAGE); sourceImageBase64 = Buffer.from(fileData).toString('base64'); } catch (e) { console.error(`❌ Image read failed: ${e.message}`); return; } const startTime = Date.now(); let resultImageBase64 = null; console.log(`\n---------------------------------------------------------`); console.log(`⏳ Requesting Ollama API (this may take a few seconds to minutes)...`); try { // 2. Call Ollama API (enable stream: true to show progress) const response = await ollama.generate({ model: MODEL, prompt: PROMPT, images: [sourceImageBase64], // 【Key】Pass source image as Base64 stream: true }); // 3. Process streaming response for await (const part of response) { // Print progress bar if (part.completed && part.total) { const percent = Math.round((part.completed / part.total) * 100); process.stdout.write(`\r🚧 Generation progress: ${percent}% [${'#'.repeat(Math.floor(percent/5))}${' '.repeat(20 - Math.floor(percent/5))}]`); } // Capture generated image data (last response contains 'image' field) if (part.image) { resultImageBase64 = part.image; } } process.stdout.write('\n'); // New line // 4. Save result if (resultImageBase64) { const duration = ((Date.now() - startTime) / 1000).toFixed(2); const buffer = Buffer.from(resultImageBase64, 'base64'); fs.writeFileSync(OUTPUT_FILENAME, buffer); console.log(`\n✅ Success! Image saved as: ${OUTPUT_FILENAME}`); console.log(`⏱️ Duration: ${duration} seconds`); } else { console.error(`\n⚠️ Stream ended but no 'image' data found in response. Check if the model supports image generation.`); } } catch (error) { console.error(`\n❌ API call error:`, error.message); } } runImg2ImgSingle(); ``` original image for test ![original image for test](https://github.com/user-attachments/assets/f2d6254b-30f9-45f2-b2b8-9cccc6a43348) Result in v0.16.1 <img width="608" height="448" alt="Image" src="https://github.com/user-attachments/assets/c2de108c-0da0-470d-9181-e2cc34bd4d9f" /> Result in v0.17.5 <img width="1024" height="1024" alt="Image" src="https://github.com/user-attachments/assets/7dd4ac4f-dcba-47f5-8c46-5ee44d43b0d2" /> ### Relevant log output ```shell ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.17.5
GiteaMirror added the bug label 2026-04-29 10:04:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#55967