在firebase云功能中创建方形缩略图

时间:2017-11-26 20:54:08

标签: node.js imagemagick google-cloud-functions child-process

我想在将图像上传到firebase中的云存储时创建方形缩略图。我只是希望将图像的中心裁剪成方形,然后将其调整为150px x 150px。 像这样:

上传时 enter image description here

我想得到这个

enter image description here

以及何时上传

enter image description here

我想得到这个

enter image description here

我想在Firebase中这样做,但他们不是只使用Imagemagick,而是使用spawn,我无法弄清楚这两者是如何结合在一起的。

对于代码,我几乎已经从这里复制并粘贴了代码: https://github.com/firebase/functions-samples/blob/master/quickstarts/thumbnails/functions/index.js

我甚至无法成功获得图像的尺寸,那么我如何才能首先获得尺寸,并实现我想要达到的目标?

/Library/Developer/CoreSimulator/Devices/10888914-22EB-4CA7-B019-F95D5A8A6F5C/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

nnapi error: unable to open library libneuralnetworks.so
Loaded model resolved reportertensorflow/contrib/lite/kernels
/kernel_util.cc:34 input_product_scale < output_scale was not 
true.Failed to allocate tensors!(lldb) 

1 个答案:

答案 0 :(得分:4)

这是imagemagick代码行:

return spawn('convert', [tempFilePath, '-thumbnail', '200x200>', tempFilePath]);

它只是创建一个缩略图和&gt;在维度的末尾告诉它只缩小较大的文件但保持纵横比。您想在临时文件路径之前添加-gravity center -crop 200x200 + 0 + 0。我不知道它是否像, '-gravity', 'center', '-crop', '200x200+0+0'

一样简单

此外,您可能会遇到纵横比问题,但您可以尝试使用portrate和横向图像,看看你得到了什么。