Skip to content

SingleApi

Internet, programming, artificial intelligence

Menu
  • Home
  • About
  • My Account
  • Registration
Menu

n8n DrawThings

Posted on July 15, 2025

For my workflow I have integrated DrawThings, the diagram of it looks like:

Steps to reproduce:

  • Assuming n8n is in Docker and DrawThings are on the host URL, it should be http://host.docker.internal:7860/sdapi/v1/txt2img. We need to use JSON, not fields, because n8n converts them to strings, and n8n has problems with interpretation. In my case, it’s:
{
    "height": 576,
    "width": 1024,
    "seed": -1,
    "prompt": "{{ $json.output.replaceAll('"', '\'').replaceAll('\n', '') }}",
    "batch_size": 1
}
  • Next, we need to move the Base64 string to the file using the field images[0] and put it in the data field.
  • We save PNG as e.g. /tmp/{{ $now.format('yyyy-MM-dd_HH-mm-ss') }}.png
  • For conversion to WebP, we use a simple script and the SharpJS library executed as: npm run convert -- {{ $json.fileName }}
// convert.js
const fs = require('fs');
const sharp = require('sharp');

async function convertPngToJpeg(filePath) {
    const outputPath = filePath.replace(/\.png$/i, '.webp');
    const input = fs.readFileSync(filePath);

    const output = await sharp(input).webp().toBuffer();

    fs.writeFileSync(outputPath, output);
    console.log(`Converted: ${outputPath} end.`);
}

const inputPath = process.argv[2];
if (!inputPath) {
    console.error('Usage: node convert.js <path-to-png>');
    process.exit(1);
}

convertPngToJpeg(inputPath);
  • The next thing is to get the filename from stdout.: {{ $json.stdout.match(/Converted: (.*) end./)[1] }} and pass it as filename
  • The last link is to read WebP, for example, sending it to WordPress (using the filename from the previous step).

Hope it helps or inspires someone to use different tools 🙂

EDIT: I have added watermark – still probably I will need to play a bit with alpha, and sizes:

// convert.js
const fs = require('fs');
const sharp = require('sharp');

async function convertPngToJpeg(filePath) {
    const outputPath = filePath.replace(/\.png$/i, '.webp');

    const { width, height } = await sharp(filePath).metadata();

    const watermark = `
    <svg width="${width}" height="${height}">
      <style>
        .watermark {
          fill: rgba(255,255,255,0.4);        /* main text color */
          font-size: 18px;
          font-family: sans-serif;
          stroke: rgba(100,100,100,0.4);            /* outline color */
          stroke-width: 1px;                  /* thickness of outline */
          paint-order: stroke fill;           /* ensure stroke is drawn     under fill */
        }
      </style>
      <text x="${width - 20}" y="${height - 20}" text-anchor="end" class="watermark">
        AI generated
      </text>
    </svg>
    `;

    await sharp(filePath)
      .composite([{ input: Buffer.from(watermark) }])
      .toFile(filePath + '_wm');

    const input = fs.readFileSync(filePath + '_wm');                             
    const output = await sharp(input).webp().toBuffer();            
                                                                                 
    fs.writeFileSync(outputPath, output);                                        
    console.log(`Converted: ${outputPath} end.`);       
}                                                                                
                                                                                 
const inputPath = process.argv[2];                  
if (!inputPath) {                                       
    console.error('Usage: node convert.js <path-to-png>');
    process.exit(1);                                      
}                                                       
                                                          
convertPngToJpeg(inputPath);   

1 thought on “n8n DrawThings”

  1. adrian says:
    August 18, 2025 at 4:47 pm

    Because I had to recreate that workflow I spot that some script info is missing – you need to in container:
    – npm install sharp
    – add to package.json
    {
    "scripts": {
    "convert": "node convert.js"
    }
    }

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • AI Developments Across Multiple Domains
  • AI Industry Highlights: New Models, Tools, and Research Breakthroughs
  • AI Research Highlights: Agentic Reasoning, Tool-Augmented LLMs, and Multimodal Capabilities
  • OpenAI Releases Realtime API for Advanced Voice Agents
  • AI Model Advancements Drive Industry Progress

Recent Comments

  • adrian on n8n DrawThings
  • adrian on Kokoro TTS Model, LLM Apps Curated List
  • adrian on Repo Prompt and Ollama
  • adrian on A Content Creation Assistant

Archives

  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • November 2023
  • May 2022
  • March 2022
  • January 2022
  • August 2021
  • November 2020
  • September 2020
  • April 2020
  • February 2020
  • January 2020
  • November 2019
  • May 2019
  • February 2019

Categories

  • AI
  • Apple Intelligence
  • Claude
  • Cursor
  • DeepSeek
  • Gemini
  • Google
  • Graphics
  • IntelliJ
  • Java
  • LLM
  • Made in Poland
  • MCP
  • Meta
  • n8n
  • Open Source
  • OpenAI
  • Programming
  • Python
  • Repo Prompt
  • Technology
  • Uncategorized
  • Vibe coding
  • Work

agents ai apps automation blender cheatsheet claude codegen comfyui deepseek docker draw things flux gemini gemini cli google hidream hobby huggingface hugging face java langchain4j llama llm mcp meta mlx movies n8n news nvidia ollama openai personal thoughts quarkus rag release repo prompt speech-to-speech spring stable diffusion tts vibe coding whisper work

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Terms & Policies

  • Privacy Policy

Other websites: jreactor

©2025 SingleApi | Design: Newspaperly WordPress Theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT