Base 64 Images with Node and JIMP

Base 64 Images with Node and JIMP

Creating string representations of images that you can embed in HTML or CSS

JIMP is the JavaScript Image Manipulation Program which is actually an NPM package, and one of its many features is the ability to create a Base 64 string from an image file. This has various uses (some nefarious…) and in this post I will demonstrate embedding a Base 64 encoded graphic as an img src in an HTML document. This is useful for small images such as logos or button graphics to reduce the number of HTTP requests, and although I am using HTML the Base 64 string can also be used in CSS.

As you probably know, base 10 (decimal) uses digits 0–9, and base 16 (hexadecimal) uses digits 0–9 plus the letters A-F. Base 64 of course needs 64 different characters and uses the 26 upper case letters, 26 lower case letters, numbers 0–9 and the plus and forward slash characters, as well as the equals sign for padding. (There are also a few other less common standards.) Therefore any code converting a file, stream or buffer to Base 64 will provide a string containing only ASCII characters which can be safely transmitted using any protocol.

For this project I will write a pair of simple functions which open an image file, obtain its Base 64 encoding, and then insert it into an HTML document. You can grab the source code from the Github repository.

image-processing web-development nodejs programming javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer](https://hourlydeveloper.io/hire-dedicated-node-js-developer/ "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

What Garbage Collection in JavaScript Is and How It Works

JavaScript values are allocated when things are created (objects, Strings, etc.) and freed automatically when they are no longer used. This process is called Garbage collection.