Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using http.DetectContentType to inter the image type #13

Closed
h2non opened this issue Mar 18, 2015 · 5 comments
Closed

Consider using http.DetectContentType to inter the image type #13

h2non opened this issue Mar 18, 2015 · 5 comments

Comments

@h2non
Copy link

h2non commented Mar 18, 2015

Probably this algorithm will be more reliable than checking the first chunk of bytes of the image:
http://golang.org/src/net/http/sniff.go?s=648:690#L11

h2non added a commit to h2non/vips that referenced this issue Mar 18, 2015
h2non added a commit to h2non/vips that referenced this issue Mar 18, 2015
h2non added a commit to h2non/vips that referenced this issue Mar 18, 2015
@lovell
Copy link
Collaborator

lovell commented Mar 18, 2015

"more reliable than checking the first chunk of bytes"

If you're happy with the minimum version of libvips being 7.40.0+, I recommend using vips_foreign_find_load_buffer for this purpose as it performs some basic verification of image metadata also - see https://github.com/lovell/sharp/blob/judgement/src/common.cc#L40

@h2non
Copy link
Author

h2non commented Mar 18, 2015

That's a good idea and probably better than Go net/http implementation just because it only checks image types. I'll support it. The restriction with libvips minimum required version is not a big deal

@lovell
Copy link
Collaborator

lovell commented Mar 18, 2015

Great, thanks Tomás.

vips_foreign_find_load_buffer has the added advantage of providing a run-time check of formats available at compile time. For example, if libvips is compiled without WebP support and is therefore unable to decode that format then this method won't detect it.

@h2non
Copy link
Author

h2non commented Mar 18, 2015

That's absolutely fantastic. In fact, I experimented some troubles yesterday with that because my original libvips compilation has no support for webp, so I was getting a nil pointer dereference runtime panic, which is very ugly. Using that function I can handle that cases better with a graceful error

@h2non
Copy link
Author

h2non commented Apr 7, 2015

@lovell I've finally supported your proposal:
https://github.com/h2non/bimg/blob/master/vips.go#L172

Thanks!

@h2non h2non closed this as completed Apr 7, 2015
xinuc added a commit to bukalapak/vips that referenced this issue Nov 30, 2016
* 'master' of https://github.com/h2non/vips:
  feat(DAddYE#12): add libwebp install in docs
  feat(DAddYE#13): support webp images
  fix: test
  fix(DAddYE#13): test
  feat(DAddYE#13): infer image type with go net/http primitive
  feat(DAddYE#12): initial support for webp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants