From 34101566094d92b0e08a8795730794b9ec849b3c Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Mon, 30 Apr 2018 05:16:01 +0200 Subject: [PATCH] Properly set image profiles Signed-off-by: Janne Koschinski <janne@kuschku.de> --- main.go | 10 ++++++++-- util.go | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 24391d4..23ad1ab 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 9cb4d78..729a407 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 -- GitLab