jimmynicol / image-resizer

On-the-fly image resizing using Node.js and GraphicsMagick. Heroku Ready!
MIT License
340 stars 105 forks source link

Error: Input buffer contains unsupported image format #64

Closed stathischaritos closed 9 years ago

stathischaritos commented 9 years ago

I get this error when I try to resize a gif image, on heroku.

This seems to be related to sharp and libvips https://github.com/lovell/sharp/issues/162

The version used is later than the one they suggest.

I tried changing the .buildpack to get a newer libvips version but it still gave the same error.

Does anyone else have the same issue?

PS. Great work, extremely valuable project.

saintberry commented 9 years ago

I do know sharp can't write gifs. It can however stream gifs through imagick and resize the first frame as .jpg or something else (https://github.com/lovell/sharp/pull/165). But it can't write gifs. This means post move to sharp the supported image formats array has a bug in it: https://github.com/jimmynicol/image-resizer/blob/master/src/image.js#L62

I'm trying to find the time to do some modifications to fix this. I'm considering a few approaches:

  1. Don't allow resizes of gifs but allow the original source to be passed back to users (useful for animated gifs). I would 404 if any request came through for a gif with a modifier. This is as simple as not using streams.resize(), streams.filter() or streams.optimize() for *.gif requests in index.js (bypass the sharp portion of the application)
  2. Allow resizing of the first frame for a gif through sharps support for streaming gifs through imagick, use imagick to save the result - this is risky as it uses a lot of memory
  3. Use something like http://www.lcdf.org/gifsicle/ to resize and save the animated gifs based on the image-resizer modifiers

I'll probably end up with 1 as I'm time poor at the moment.

jimmynicol commented 9 years ago

@saintberry I would probably suggest 1. is the most pragmatic choice too, but then it begs the question of why bother going through the resizer at all.

The use cases I have had for this project rarely ended up needing gif support, and as mentioned resizing animated gifs never works well. The move to sharp just had too many plus sides to consider gifs.

So I would probably prefer not supporting gifs at all, using the same CDN -> custom source setup to s3 for instance would provide just as good a solution as letting them pass through image-resizer.

teohhanhui commented 8 years ago

For anyone interested, we have decided to maintain our own fork: https://github.com/tripviss/image-resizer

We've added a "normalize" step in tripviss/image-resizer#12

(Yes, the conversion to PNG has a performance hit, but that's the best we can do at the moment.)

So you can now use GIF and TIFF as input, but be sure to specify a supported output format. Of course, GIF output is still not supported.