Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-base64-image

riyadhalnur60.3kMIT2.2.0TypeScript support: included

Download images from remote URLs and encode/decode them to base64

image, download, base64, encode, decode, javascript, node, nodejs, js, buffer

readme

Node.js Package
NPM Version NPM Downloads

node-base64-image

Easily encode images (from URLs or local files) to Base64 strings or Buffer objects, and decode them back into image files.

Installation

npm install node-base64-image --save

Usage

// CommonJS:
const { encode, decode } = require('node-base64-image');

// ES Modules / TypeScript:
import { encode, decode } from 'node-base64-image';

EncodeOptions

Attribute Type Description Default Value
string boolean If true, returns a base64 string false
local boolean Set to true to read from a local file -
timeout number Request timeout in milliseconds 5000
headers object Optional headers for remote HTTP requests -

DecodeOptions (Required)

Attribute Type Description Default Value
fname string Output filename (without extension) -
ext string File extension (e.g., jpg, png) -

Examples

// encoding a remote jpg to base64
const url = 'https://example.com/test.jpg';
const options = {
  string: true,
  headers: {
    "User-Agent": "my-app"
  }
};
const image = await encode(url, options);

// encoding a local file
const localUrl = 'C:/project/test.jpg';
const localImage = await encode(url, {string: true, local: true});

// writing to file named 'example.jpg'
await decode(image, { fname: 'example', ext: 'jpg' });

// writing to a sub-directory
// after creating a directory called 'photos'
const image = await encode(url, options);
await decode(image, { fname: './photos/example', ext: 'jpg' });

Contributing

Read the CONTRIBUTING guide for information.

License

Licensed under MIT. See LICENSE for more information.

Issues

Report a bug in issues

Made with love in Dhaka, Bangladesh by Riyadh Al Nur

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v2.0.7

v2.0.7

15 August 2024

  • fix: Updated dependencies to remove vulnerabilities #79
  • Update README.md to include example for encoding from local file #77
  • Bump follow-redirects from 1.15.4 to 1.15.6 #75
  • Bump follow-redirects from 1.15.2 to 1.15.4 #74
  • fix: Updated dependencies to remove vulnerabilities #78 d6a368b
  • Update npm-test-publish.yaml 65f8463
  • Bump package and drop support for v16 5e87fb5

v2.0.6

12 November 2023

  • Update npm-test-publish.yaml #71
  • Bump axios from 1.3.5 to 1.6.0 #70
  • Bump @babel/traverse from 7.21.4 to 7.23.2 #68
  • Bump word-wrap from 1.2.3 to 1.2.4 #67
  • Bump package a078bbe

v2.0.5

13 April 2023

v2.0.4

29 January 2022

  • [Snyk] Security upgrade axios from 0.21.1 to 0.21.3 #60
  • Update README.md #55
  • UPDATED: update deps 1e262ab
  • fix: package.json & package-lock.json to reduce vulnerabilities d257bce
  • Create SECURITY.md 73448cd

v2.0.3

20 January 2021

v2.0.2

18 January 2021

  • [Snyk] Security upgrade axios from 0.19.2 to 0.21.1 #56
  • Bump lodash from 4.17.15 to 4.17.19 #54
  • CHORE: update outdated deps e7dfdd1
  • fix: package.json & package-lock.json to reduce vulnerabilities 6fe9230
  • Updated CHANGELOG e5fabdd

v2.0.1

26 May 2020

v2.0.0

26 May 2020

  • Add new dependencies 548f628
  • Remove old and unecessary files 87127f3
  • Rewrite package in typescript 57b828d

v1.0.7

13 February 2020

v1.0.6

1 June 2019

  • [Snyk] Fix for 1 vulnerable dependencies #36
  • Update packages and bump version 0f73780
  • CI node versions update 0e5466b
  • declare type a4ebdd1

v1.0.5

22 April 2018

  • Bump package version to use vulnerability fixes #34
  • [Snyk Update] New fixes for 4 vulnerable dependency paths #32
  • [Snyk Update] New fixes for 1 vulnerable dependency path #31
  • Update packages and add package lock add73c0
  • Test node version to test against on travis 4532e16
  • fix: package.json to reduce vulnerabilities 57fd98a

v1.0.4

7 July 2017

  • [Snyk Update] New fixes for 1 vulnerable dependency path #28
  • fix: package.json to reduce vulnerabilities 75c9359

v1.0.3

4 November 2016

  • Increase timeout for tests cb0e8d4

v1.0.2

3 November 2016

  • [Snyk Alert] Fix for 1 vulnerable dependency path #22
  • Generate dist/ a631f97
  • fix: package.json & .snyk to reduce vulnerabilities c50075c

v1.0.1

28 May 2016

v1.0.0

28 May 2016

  • ES6 rewrite #15
  • Create PR template #17
  • Create Issue Template #16
  • Set up initial ES6 boilerplate 2bb6f3d
  • Finished re-writing main encode and decode funcs bb2b5cf
  • Streamline build process a834070

0.1.2

27 February 2016

  • Handle image loading failure (empty body or statusCode other than 200) #7
  • Test added for 404 case 27d1ff8
  • Release 0.1.2 0c204e6

0.1.1

9 November 2015

  • README fixes #6
  • Fix first example code 98dac6e
  • Added newer version of Node for Travis 0b6ba64

0.1.0

17 September 2015

  • Bump version 47cb1dd
  • added option to encode a local file c9cd5df
  • codestyle fixes, added test.jpg, fixed tests 2ab6af0

0.0.1

13 December 2014