Thumbnail the first page of a pdf from a stream in GraphicsMagick

只愿长相守 提交于 2019-12-07 15:39:26

You can use .selectFrame() method, which is equivalent to specifying [0] directly in file name.

In your code:

function transform(response, next) {
    gm(response.Body)
        .selectFrame(0)       // <--- select the first page
        .size(function(err, size) {
        .
        .
        .

Don't get confused about the name of function. It work not only with frames for GIFs, but also works just fine with pages for PDFs.

Checkout this function source on GitHub.

Credits to @BenFortune for his answer to similar question about GIFs first frame. I've took it as inspiration and tested this solution with PDFs, it actually works.

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!