【问题标题】:GraphicsMagick .toBuffer() creates empty buffer streamGraphicsMagick .toBuffer() 创建空缓冲区流
【发布时间】:2021-09-27 10:00:25
【问题描述】:

我有一个 Firebase 云函数,它使用 GraphcisMagick 将缓冲区(从 PDF)转换为 PNG。当我尝试将此 PNG 缓冲区写入 Firebase 存储时,我得到一个文件存根,但没有内容(空文件)。我转换为 PNG 失败...

async function createThumbnail(newthumbname, mimetype, filebuffer) {
    const file = bucket.file(newthumbname)
    const thumbstream = file.createWriteStream({metadata:{contentType:mimetype}})
    const gm = require('gm').subClass({imageMagick: true})
    gm(filebuffer)
    .toBuffer('png', (err, thumbbuffer)=>{
        console.log(filebuffer)
        console.log(thumbbuffer)
        thumbstream.end(thumbbuffer)
    })
}

传入createThumbnail()filebuffer有内容,

<Buffer 25 50 44 46 2d 31 2e 33 0a 25 c4 e5 f2 e5 eb a7 f3 a0 d0 c4 c6 0a 33 20 30 20 6f 62 6a 0a 3c 3c 20 2f 46 69 6c 74 65 72 20 2f 46 6c 61 74 65 44 65 63 ... 6464 more bytes>

但是gm(filebuffer).toBuffer() 正在生产并用Error: Stream yields empty buffer 清空thumbbuffer

我在这里做错了什么?

【问题讨论】:

    标签: imagemagick firebase-storage graphicsmagick createwritestream


    【解决方案1】:

    这似乎是png 问题,因为jpg 似乎同时适用于.stream().toBuffer()

    我会选择jpg,直到我弄清楚png 有什么问题。

    async function createThumbnail(newthumbname, mimetype, filebuffer) {
        const file = bucket.file(newthumbname)
        const thumbstream = file.createWriteStream({metadata:{contentType:mimetype}})
        const gm = require('gm').subClass({imageMagick: true})
        gm(filebuffer)
        // .setFormat("jpg")
        // .stream()
        // .pipe(thumbstream)
        .toBuffer('jpg', (err, thumbbuffer)=>{
            thumbstream.end(thumbbuffer)
        })
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2021-11-21
      • 1970-01-01
      • 2011-11-14
      • 2021-10-06
      相关资源
      最近更新 更多