Skip to content

Converting a UIImage to the WebP format is extremely slow #115

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

Open
pogong opened this issue Mar 3, 2025 · 3 comments
Open

Converting a UIImage to the WebP format is extremely slow #115

pogong opened this issue Mar 3, 2025 · 3 comments

Comments

@pogong
Copy link

pogong commented Mar 3, 2025

Converting a UIImage to the WebP format is extremely slow. For a 2.5-megabyte photo with a compression ratio of 0.85, it takes approximately 13.5 seconds

let webpCoder = SDImageWebPCoder.shared
var options: [SDImageCoderOption: Any] = [:]
options[SDImageCoderOption.encodeCompressionQuality] = 0.85

if let webpData = webpCoder.encodedData(with: image, format: .webP, options: options) {
compressionImageData = webpData
}

@dreampiggy
Copy link
Contributor

Image encoding takes more time than JPEG, it's a by-design behavior.

You can upgrade libwebp version instead, or more

We can added something like cwebp 's -m [method] API, which allows you to control the speed-compression tradeoff. The more method you provided, the less compression ratio and faster speed you gain. (Means, fast encoding speed produce larger webp file)

@pogong
Copy link
Author

pogong commented Mar 3, 2025

Image encoding takes more time than JPEG, it's a by-design behavior.

You can upgrade libwebp version instead, or more

We can added something like cwebp 's -m [method] API, which allows you to control the speed-compression tradeoff. The more method you provided, the less compression ratio and faster speed you gain. (Means, fast encoding speed produce larger webp file)

I get. SDWebImageWebPCoder dependency on libwebp for conver UIImage to WebP. libwebp version I import is too low. I will upgrade it and try again.
libwebp (~> 1.0)

For [added something like cwebp], The ultimate goal is to have a very small file size for uploading. We won't consider it if the file is too large.

@dreampiggy
Copy link
Contributor

You can have a try. But anyway, maybe provide some detailed control options like the Google official CLI tool is a OK feature request

https://developers.google.com/speed/webp/docs/cwebp

-m int
Specify the compression method to use. This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. Default value is 4. When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Lower value can result in faster processing time at the expense of larger file size and lower compression quality.

I can have a check whether it's suitable and easy to implements. Recently I provided the similar encoding options on libjxl codec (in https://github.com/SDWebImage/SDWebImageJPEGXLCoder?tab=readme-ov-file#advanced-jxl-codec-options)

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