pressly / imgry

On-demand image sizing+delivery for responsive applications
MIT License
157 stars 15 forks source link

Fast gif resize #8

Open pkieltyka opened 9 years ago

pkieltyka commented 9 years ago

https://github.com/pressly/imgry/blob/f7a2a8c41a15417782a37f4fbc3a90a2ef34c20f/imagick/imagick.go#L195-L199

pkieltyka commented 9 years ago

The current imagick implementation for gif resizing will flatten each layer, which creates a larger in filesize image, and is MUCH slower to resize because it effectively resizes more bytes per frame to generate the image.

For example: http://imgry.pressly.com/test/fetch?url=http%3A%2F%2Fwww.thisiscolossal.com%2Fwp-content%2Fuploads%2F2015%2F04%2Fcine-1.gif&size=800x

this will load quickly because its already sized/cached -- but, try to change the size query param to 840x or 730x .. pick something ... it will take over 2 seconds. And compare the filesize to the original image url: http://www.thisiscolossal.com/wp-content/uploads/2015/04/cine-1.gif

if you open the gif in an image editor, you will see the layers (frames), the subsequent frames are actually offset positions, layered on top of eachother. Other gifs do use full frames and a 0,0 offset.

The goal is to not have to flatten each frame, and try to keep the frames intact, and resize the respective layers etc. to get the final image.

xiam commented 9 years ago

Closed by https://github.com/pressly/imgry/pull/9?