davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.25k stars 196 forks source link

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

Open prashik-s opened 11 months ago

prashik-s commented 11 months ago

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 commented 8 months ago

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

tonimelisma commented 6 months ago

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

prashik-s commented 6 months ago

closes #410

prashik-s commented 6 months ago

@tonimelisma Can you review?