diff --git a/main.go b/main.go index 24391d46cb91244555b7c25dac40572a7cf633c9..23ad1ab11cbe3c0a90cfd3ccfd3872d584bb65de 100644 --- a/main.go +++ b/main.go @@ -19,11 +19,12 @@ func returnResult(config *Config, client *redis.Client, result Result) { client.Publish(config.ResultChannel, string(raw)) } -func generateSize(errorChannel chan error, wand *imagick.MagickWand, wandLinear *imagick.MagickWand, colorSpace imagick.ColorspaceType, config *Config, image Image, definition SizeDefinition) { +func generateSize(errorChannel chan error, wand *imagick.MagickWand, wandLinear *imagick.MagickWand, colorSpace imagick.ColorspaceType, profiles map[string]string, config *Config, image Image, definition SizeDefinition) { errorChannel <- resize( wand, wandLinear, colorSpace, + profiles, definition.Size, config.Quality, filepath.Join(config.TargetFolder, fmt.Sprintf("%s%s", image.Id, definition.Suffix)), @@ -55,13 +56,18 @@ func processImage(config *Config, client *redis.Client, value string) { colorSpace = imagick.COLORSPACE_SRGB } + profiles := map[string]string{} + for _, name := range wand.GetImageProfiles("*") { + profiles[name] = wand.GetImageProfile(name) + } + err = wandLinear.TransformImageColorspace(imagick.COLORSPACE_RGB) if err != nil { panic(err) } for _, definition := range config.Sizes { - go generateSize(errorChannel, wand, wandLinear, colorSpace, config, image, definition) + go generateSize(errorChannel, wand, wandLinear, colorSpace, profiles, config, image, definition) } errors := make([]string, 0) diff --git a/util.go b/util.go index 9cb4d783694c03de451d5985087bf3095aba14e0..729a40707b4bfe436724be34f344235c3e65c806 100644 --- a/util.go +++ b/util.go @@ -7,7 +7,7 @@ import ( "math" ) -func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, originalColorSpace imagick.ColorspaceType, size Size, quality Quality, target string) error { +func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, originalColorSpace imagick.ColorspaceType, profiles map[string]string, size Size, quality Quality, target string) error { var err error var mw *imagick.MagickWand @@ -90,6 +90,10 @@ func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, originalCo } mw.StripImage() + for key, value := range profiles { + mw.SetImageProfile(key, []byte(value)) + } + err = mw.WriteImage(target) return err