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

x/image/webp: support for WebP Encoding #45121

Open
ainsleyclark opened this issue Mar 19, 2021 · 19 comments
Open

x/image/webp: support for WebP Encoding #45121

ainsleyclark opened this issue Mar 19, 2021 · 19 comments
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@ainsleyclark
Copy link

Hi there,

Currently we are able to decode webp images, which is great. But why can't we encode them?

Given that PSI is such a crucial factor for getting websites to rank, it's important that any server should be able to convert and serve webp images.

I have to jump through hoops at the moment and use the webp executable which is far from ideal.

Please please add an encoder!

Many many thanks.

@ainsleyclark ainsleyclark changed the title Support for WebP Encoding x/image Support for WebP Encoding Mar 19, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 19, 2021
@ALTree ALTree changed the title x/image Support for WebP Encoding x/image: support for WebP Encoding Mar 19, 2021
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 19, 2021
@ALTree
Copy link
Member

ALTree commented Mar 19, 2021

cc @nigeltao

@ianlancetaylor
Copy link
Contributor

A WebP encoder would be a lot of work. If someone wants to write one, that would be great. But as far as I know nobody is working on that.

@ainsleyclark
Copy link
Author

That's a shame, whilst I understand that it may be a bit of work, it feels like it should be out of the box considering webp and go are both made by you guys!

Adding C bindings when converting to webp using third party packages can be messy, as well as using the executables.

I would love to offer a hand to contribute to the /x/image library but wouldn't know where to start.

@nigeltao
Copy link
Contributor

I understand that it may be a bit of work

It's not a bit of work. As Ian said, it's a lot of work. :-)

@DemiMarie
Copy link

That's a shame, whilst I understand that it may be a bit of work, it feels like it should be out of the box considering webp and go are both made by you guys!

Adding C bindings when converting to webp using third party packages can be messy, as well as using the executables.

The good news is that image encoding is much less of a security minefield than image decoding is, simply because the input format (a bitmap) is far, far simpler.

That said, have you considered ImageFlow? It’s free software (AGPL) available as both a daemon and a library. Commercial licenses are also available.

@ainsleyclark

This comment was marked as duplicate.

@ivanjaros

This comment was marked as duplicate.

@FlavioCFOliveira

This comment was marked as spam.

@ivanjaros

This comment was marked as duplicate.

@NinoM4ster
Copy link

NinoM4ster commented Sep 23, 2022

Starting a new website project with a Go backend and was planning on using WebP for image thumbnails and it's really sad to see that there's no native encoder.. :(

I would really like to avoid using C bindings (due to performance and memory safety concerns), but it seems that's the only option at the moment, except for executing the official webp binary, which is also not the best idea, since you'd have to either write the file to disk or come up with a complicated virtual FS just for it.

I also considered using Rust, but that's way too advanced for me.

Edit: I found https://github.com/nickalie/go-webpbin which seems quite decent. haven't tested it yet though.

@ainsleyclark

This comment was marked as duplicate.

@ivanjaros

This comment was marked as duplicate.

@ex-tag

This comment was marked as duplicate.

@ex-tag

This comment was marked as duplicate.

@ex-tag

This comment was marked as off-topic.

@ainsleyclark

This comment was marked as off-topic.

@seankhliao seankhliao changed the title x/image: support for WebP Encoding x/image/webp: support for WebP Encoding Jan 30, 2023
@wjkoh
Copy link

wjkoh commented Jan 6, 2024

Could go-libwebp by Jack Mordaunt offer a potential solution? I'm aware that rewriting libwebp in Go would be quite time-consuming, but Jack Mordaunt utilized ccgo and was able to port the libwebp C code to native Go code, making it functional, if I understand correctly. I'm not an expert, and I'm unsure of any potential risks this approach may present, but I wanted to share the idea. @JackMordaunt

@dastanaron
Copy link

dastanaron commented Jan 6, 2024

I think there is a better solution. Example may use c-bindings from library on C language.

@JackMordaunt
Copy link

JackMordaunt commented Jan 8, 2024

Could go-libwebp by Jack Mordaunt offer a potential solution? I'm aware that rewriting libwebp in Go would be quite time-consuming, but Jack Mordaunt utilized ccgo and was able to port the libwebp C code to native Go code, making it functional, if I understand correctly. I'm not an expert, and I'm unsure of any potential risks this approach may present, but I wanted to share the idea. @JackMordaunt

Thanks for the reference!

Yes, it's functional. However there's a lot of downside to the transpilation approach which bars it from being anything official.

  • it relies on ccgo for transpilation, an experimental tool under active development
  • it generates Go code semantically identical to the C source, everything is a uintptr and thus totally unsafe
  • no support for vectorized instructions, or any inline assembly. This makes it a decent amount slower (without benchmarks its hard to say how much slower, but it definitely is)

For anyone interested, go-libwebp also allows calling into dynamic libraries if available. However this uses purego to make those calls without requiring cgo. purego is also an experimental tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests