Jay P
Jay P

Reputation: 626

Node Js NPM sharp. cannot write .gif to file

I am currently making an image resizer for a website (it resizes an image based on the the width of the container it is in).

I can successfully save and server jpeg's and png's however i cannot seem to save .gif's to a file.

This code works for the jpg's and png's

    sharp(imgPath)
      .resize(containWidth, Null)
      .withoutEnlargement()
      .toFile(modImgPath, function(err) {
        if(err){console.log(err)}
      }); 

I can get the gif's to display in the browser (With the code below) however i cannot save them to file.

    sharp(imgPath)
      .resize(modImgPath, null)
      .withoutEnlargment()
      .toBuffer(function(err, outputBuffer) {
        if (err) {console.log(err)}
      }

Iv looked into how to save image buffers to file however nothing seems to work.

Upvotes: 0

Views: 4572

Answers (1)

Stathis Charitos
Stathis Charitos

Reputation: 21

Currently the gif output seems to be unsupported in sharp.

https://github.com/lovell/sharp/issues/162

https://github.com/lovell/sharp/issues/245

One solution, though I haven't tried to see if it works, is to change the output to another format. This will save the first frame of your gif.

Upvotes: 2

Related Questions