简体   繁体   English

什么更有效地调整图像大小并将其转换为 base64 或转换为 base64 然后调整其大小? (node.js - 没有画布)

[英]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).我有一组本地文件,必须调整大小然后转换 yo base64(在服务器端,使用 nodejs 并且不支持 canvas)。 I wonder with approach is more eficient (fast and less RAM consuming):我想知道这种方法更有效(快速且消耗更少的 RAM):

  1. Read file to base 64 using fs.readFileSync(path, 'base64');使用 fs.readFileSync(path, 'base64'); 将文件读取到 base 64;
  2. Resize the base64 to other base64将 base64 调整为其他 base64

Or:或者:

  1. Resize the image (using sharp or a similar npm packet.调整图像大小(使用清晰或类似的 npm 数据包。
  2. Read the resized image as base64.将调整大小的图像读取为 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.正如已经评论的那样:即使图像处理库允许您传递图像的 base64 编码版本并直接对其进行处理,在幕后它总是将 base64 解码为图像格式,进行处理(调整大小)和然后可能会再次对其进行编码,因此从 b64 开始肯定会更慢。

Answering the original question - in terms of fast and efficiency is better:回答原始问题 - 就快速和效率而言更好:

  1. Resize the image (using sharp or a similar npm packet调整图像大小(使用sharp或类似的npm数据包
  2. Convert the resized image to base64将调整大小的图像转换为 base64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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