Skip to content
Snippets Groups Projects
Verified Commit d7ade9fd authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Improve colorspace handling

parent ff0c49f4
No related branches found
No related tags found
No related merge requests found
package main
import (
"github.com/go-redis/redis"
"encoding/json"
"os"
"gopkg.in/gographics/imagick.v2/imagick"
"fmt"
"github.com/go-redis/redis"
"gopkg.in/gographics/imagick.v2/imagick"
"net/http"
"os"
"path/filepath"
"time"
"net/http"
)
func returnResult(config *Config, client *redis.Client, result Result) {
......@@ -19,10 +19,11 @@ 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, config *Config, image Image, definition SizeDefinition) {
func generateSize(errorChannel chan error, wand *imagick.MagickWand, wandLinear *imagick.MagickWand, colorSpace imagick.ColorspaceType, config *Config, image Image, definition SizeDefinition) {
errorChannel <- resize(
wand,
wandLinear,
colorSpace,
definition.Size,
config.Quality,
filepath.Join(config.TargetFolder, fmt.Sprintf("%s%s", image.Id, definition.Suffix)),
......@@ -49,13 +50,19 @@ func processImage(config *Config, client *redis.Client, value string) {
wandLinear := wand.Clone()
defer wandLinear.Destroy()
colorSpace := wand.GetImageColorspace()
if colorSpace == imagick.COLORSPACE_UNDEFINED {
colorSpace = imagick.COLORSPACE_SRGB
}
println(colorSpaceName(colorSpace))
err = wandLinear.TransformImageColorspace(imagick.COLORSPACE_RGB)
if err != nil {
panic(err)
}
for _, definition := range config.Sizes {
go generateSize(errorChannel, wand, wandLinear, config, image, definition)
go generateSize(errorChannel, wand, wandLinear, colorSpace, config, image, definition)
}
errors := make([]string, 0)
......
......@@ -59,29 +59,17 @@ func colorSpaceName(colorSpace imagick.ColorspaceType) string {
}
}
func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, size Size, quality Quality, target string) error {
func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, originalColorSpace imagick.ColorspaceType, size Size, quality Quality, target string) error {
var err error
var mw *imagick.MagickWand
var colorSpace imagick.ColorspaceType
if size.Width == 0 && size.Height == 0 {
mw = wand.Clone()
defer mw.Destroy()
colorSpace = mw.GetImageColorspace()
if colorSpace == imagick.COLORSPACE_UNDEFINED {
colorSpace = imagick.COLORSPACE_SRGB
}
} else {
mw = wandLinear.Clone()
defer mw.Destroy()
colorSpace = mw.GetImageColorspace()
if colorSpace == imagick.COLORSPACE_UNDEFINED {
colorSpace = imagick.COLORSPACE_SRGB
}
width := mw.GetImageWidth()
height := mw.GetImageHeight()
......@@ -138,7 +126,7 @@ func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, size Size,
return err
}
err = mw.TransformImageColorspace(colorSpace)
err = mw.TransformImageColorspace(originalColorSpace)
if err != nil {
return err
}
......@@ -163,7 +151,6 @@ func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, size Size,
mw.SetImageProfile("IPTC", []byte(iptcProfile))
}
println(colorSpaceName(colorSpace))
err = mw.WriteImage(target)
return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment