Skip to content

Basic GIF support#346

Merged
jimlambie merged 4 commits intodevelopfrom
feature/gif-support
May 11, 2018
Merged

Basic GIF support#346
jimlambie merged 4 commits intodevelopfrom
feature/gif-support

Conversation

@jimlambie
Copy link
Copy Markdown
Contributor

@jimlambie jimlambie commented May 2, 2018

This PR gives CDN basic GIF support, which we lost in the switch of image processor.

It uses Jimp to load the final output buffer from Sharp, and uses https://github.com/jtlapp/gifwrap to generate a GIF frame and finally do the encoding before returning the buffer to the consumer.

No configurable image parameters have been taken into account, such as options for dithering, colour quantize method, etc.

Issue #257 suggests additional requirements such as cropping an animated GIF and selecting a poster frame. Requirements for these should be written up as new tickets, and perhaps implemented as plugins cc @abovedave @adamkdean

Close #257

* processor after applying image manipulations
* @returns {Buffer} a GIF encoded buffer
*/
ImageHandler.prototype.processGif = function (buffer) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like you don't need to create a wrapping Promise, since both Jimp.read and GifUtil.write return one already. Could you do:

return Jimp.read(buffer).then(image => {
  // (...)

  return GifUtil.write(tmpGifFile, [frame]).then(gif => {
    // (...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread dadi/lib/handlers/image.js Outdated
let tmpGifFile = `${path.join(tmpDirectory, sha1(this.parsedUrl.original.path))}.gif`

GifUtil.write(tmpGifFile, [frame]).then(gif => {
fs.unlinkSync(tmpGifFile)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this async, if possible. If you want to make it use Promises without any extra work, you could replace fs with fs-extra and do:

return fs.unlink(tmpGifFile).then()

Copy link
Copy Markdown
Contributor

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@jimlambie jimlambie merged commit f946f23 into develop May 11, 2018
@jimlambie jimlambie deleted the feature/gif-support branch May 11, 2018 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants