question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving Base64 format

See original GitHub issue

Excellent library!!!

Two quick questions.

  1. Is there a way to save a Base64 image in a string variable as a resized image?
  2. are there available option(s) to read an image file (.jpg) and overriding it by saving a resized version of it in the same directory path?

Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

41reactions
papandreoucommented, Aug 14, 2018
  1. You can just use Buffer#toString and pass base64:
const resizedImageBuf = await require('sharp')(pathToMyImage)
  .resize(32, 32)
  .toBuffer();

console.log(`data:image/png;base64,${resizedImageBuf.toString('base64')}`);
// data:image/png;base64,iVBORw0KGgoAAAANS...

(you need to match the Content-Type with the type of the resulting image, of course)

3reactions
sonnyk22commented, Aug 16, 2018

fantastic! Another great solution to one of my issue. Thank you again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Online - Base64 Encoding of "save"
Encode "save" to Base64 format​​ Simply enter your data then push the encode button. To encode binaries (like images, documents, etc.)
Read more >
Storing image in database directly or as base64 data?
While base64 is fine for transport, do not store your images base64 encoded. Base64 provides no checksum or anything of any value for...
Read more >
Storing and displaying images with base64 | by Tung Nguyen
Base64 encoded images help to reduce number of HTTP requests. Especially, it is extremely effective for small images. Embedding base64 encoded images in...
Read more >
2.6 Saving Images and Base64 Encoding - YouTube
https://github.com/CodingTrain/Intro-to-Data-APIs-JS Let's add an image from the webcam to our database. For this project, we will be using ...
Read more >
Saving An Image As Base64 - Talking HighTech
Base64 is used to encode binary files such as images within ... In the post, we will try to save some valuable time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found