简体   繁体   中英

What is more efficiente resize an image and the convert to base64 or convert to base64 and then resize it? (node.js - no canvas)

I have a local set of files that have to resize and then convert yo base64 (in the server side, using nodejs and without canvas support). I wonder with approach is more eficient (fast and less RAM consuming):

  1. Read file to base 64 using fs.readFileSync(path, 'base64');
  2. Resize the base64 to other base64

Or:

  1. Resize the image (using sharp or a similar npm packet.
  2. Read the resized image as base64.

Thank you!

As it's have been commented: even if a image processing lib allows you to pass a base64 encoded version of an image and work on it directly, behind the scenes it will always decode the base64 into an image format, do the processing (resize) and then probably encode it again, so starting with b64 is certainly slower.

Answering the original question - in terms of fast and efficiency is better:

  1. Resize the image (using sharp or a similar npm packet
  2. Convert the resized image to base64

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM