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

When exporting to Webp, the ColorProfile is getting removed #384

Open
prashik-s opened this issue Oct 11, 2023 · 4 comments
Open

When exporting to Webp, the ColorProfile is getting removed #384

prashik-s opened this issue Oct 11, 2023 · 4 comments

Comments

@prashik-s
Copy link
Contributor

prashik-s commented Oct 11, 2023

If the input image already has an ICC Profile embedded into it, the ICC Profile is getting dropped when converting to Webp. This happens if we don't make a call to OptimizeICCProfile . The OptimizeICCProfile function updates the variable optimizedIccProfile.
While exporting a Webp, govips looks at the params for ICC Profile. If we don't send an ICC Profile in the export params and the optimizedIccProfile variable is not set, then the ICC Profile of the image is dropped.

Problematic code:

// ExportWebp exports the image as WEBP to a buffer.
func (r *ImageRef) ExportWebp(params *WebpExportParams) ([]byte, *ImageMetadata, error) {
	if params == nil {
		params = NewWebpExportParams()
	}

	paramsWithIccProfile := *params
	paramsWithIccProfile.IccProfile = r.optimizedIccProfile

	buf, err := vipsSaveWebPToBuffer(r.image, paramsWithIccProfile)
	if err != nil {
		return nil, nil, err
	}

	return buf, r.newMetadata(ImageTypeWEBP), nil
}

There should be a check here if the image has it's own ICC profile and it shouldn't be dropped.

@dmytro-brykovets-quarks-tech

Just had to fix it with OptimizeICCProfile as well. Also, this code ignores if params.IccProfile is set by the user.

@tonimelisma
Copy link
Collaborator

Thanks. Anyone have energy to create a PR? I'd be happy to merge one.

@prashik-s
Copy link
Contributor Author

closes #410

@prashik-s
Copy link
Contributor Author

@tonimelisma Can you review?

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

3 participants