Piotr Sikora - Logo - Automatyzacja procesów | AI | JavaScript | Front End | Team Leader
  • Home
  • Services
    • Process Automation
    • AI for Lawyers
  • Blog
  • Quotes
  • Contact
PL/EN

Image to HTML table. Transform image to HTML table.

  • Home
  • Blog
  • Image to HTML table. Transform image to HTML table.
Image to HTML table. Transform image to HTML table.

By Piotr Sikora

  • javascript

  • 3 min read

Table of Contents

  • How to run it
  • Github and sample

Few years ago when I was on Front trends I heard very interesting story about improvements in delivery of emailers.

Every developer knows that it isn’t easy to deliver complex email template. But one of the developers made a story about images in email templates. It was related with visibility of company when email client has blocked images and he cannot see the company logo because he can read only text from email. So how to deliver it without image? HTML TABLE!!!

It made me to create this simple script which will create a colorful HTML Table from source image.

var Jimp = require("jimp");

    var imagePath = process.argv[2];

    function rgb2hex(rgb){
     rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
     return (rgb && rgb.length === 4) ? "#" +
      ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
      ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
      ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
    }

    Jimp.read(imagePath, function (err, image) {
        if (err) {
          console.log(err);
        } else {
          console.log('<table style="border-collapse: collapse; width: '+image.bitmap.width+'px; border: 0">');

          for (var j=0; j<image.bitmap.height; j++)="" {="" console.log('<tr="">');

            for (var i= 0; i < image.bitmap.width; i++ ) {
              var pixelColor = Jimp.intToRGBA(image.getPixelColor(i, j));

              console.log('<td style="height: 1px; width: 1px; padding: 0; border: 0; background-color:');
              console.log( rgb2hex('rgb('+pixelColor.r+','+pixelColor.g+','+pixelColor.b+')') );
              console.log('"></td>');
            }
            console.log('');
          }

          console.log('</image.bitmap.height;></table>')
        }
    });

How to run it

All you need is to run this code inside folder with source code:

node index.js images/logo.png &gt; test.html

Github and sample

Here you can find code on GitHub.

Here you can find sample table.

Enjoy!

Share this article

TwitterLinkedInFacebook

Tags:

  • #image2htmltable

  • #javascript

  • #js

  • #nodejs

Categories

after-hours(1)AI(7)ai-en(1)angular(4)automatic-tests(1)Automation(2)cryptography(1)css(8)CyberSecurity(2)Development(6)DevOps(1)events(3)javascript(11)n8n(10)ollama(1)security(2)seo(1)

Recent Posts

Testing Kimi Code: First Impressions from Web and CLI

Development

Testing Kimi Code: First Impressions from Web and CLI

Why You Shouldn't Cram Multiple Webhooks Into One n8n Workflow

Automation

Why You Shouldn't Cram Multiple Webhooks Into One n8n Workflow

DRY, WET, AHA: Finding the Right Balance in Code Reuse

Development

DRY, WET, AHA: Finding the Right Balance in Code Reuse

API vs Webhook: Understanding the Difference

Development

API vs Webhook: Understanding the Difference

RTCROS Framework: Structure Your Prompts for Better AI Results

AI

RTCROS Framework: Structure Your Prompts for Better AI Results

About Me

Piotr Sikora - Process Automation | AI | n8n | Python | JavaScript

Piotr Sikora

Process Automation Specialist

I implement automation that saves time and money, streamlines operations, and increases the predictability of results. Specializing in process automation, AI implementation, and workflow optimization using n8n, Python, and JavaScript.

n8n Workflows

n8n workflow automation templates

Explore my workflow templates on n8n. Ready-to-use automations for blog management, data collection, and AI-powered content processing.

3Workflow Templates
View Templates

• Auto-Categorize Blog Posts with AI

• Collect LinkedIn Profiles

• Export WordPress Posts for SEO

Tags

activepiecesafter-hoursahrefsaiAI cost reductionai-agentsai-automationangularantigravityapiAqua Securityarcade-gamesarchitectureautomationbackendbest-practicescadillacs-and-dinosaurschatbotchatgptCI/CD
“Whether you think you can or you think you can't – you're right.”
Henry Ford
View more quotes

Similar Articles

Discover more related content

Unleash the Power of Autoexecuted Objects in JavaScript

Unleash the Power of Autoexecuted Objects in JavaScript

Sometimes you will need to create autoexecuted object (for example in case of load/document ready events)

31 January 2014
Pure JavaScript: Private and Public Methods Guide

Pure JavaScript: Private and Public Methods Guide

Have you been creating your own classes in pure JavaScript?

Raspberry Pi node.js and how to start with programming GPIO

Raspberry Pi node.js and how to start with programming GPIO

Start programming Raspberry Pi GPIO with Node.js. Introduction to the PixPress project on GitHub. Hardware meets JavaScript.

Piotr Sikora | ai | n8n | javascript | python

Let's get to know each other!

Get in touch with me
Piotr Sikora | Process Automation  | AI Implementation 🤖 | Technology Consulting
Quick links
  • Home
  • Blog
  • Contact
Contact
  • piotr.sikora.ck@gmail.com
  • +48 505 684 661

© Piotr Sikora 2026 | All Rights Reserved