Skip to content

Commit

Permalink
Added gradient drawing support for ImageMagick 6. (#162)
Browse files Browse the repository at this point in the history
* Added gradient drawing support.

* Update travis to use ImageMagick-6.9.9-40

* Update travis yml to derive ImageMagick version from external dashboard

* Remove unnecessary containers.
  • Loading branch information
gavbaa authored and justinfx committed Apr 2, 2018
1 parent f68f22f commit 93aac8e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/gradient/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"gopkg.in/gographics/imagick.v2/imagick"
)

// Demonstrate creating a gradient image including artifact mods.
func main() {
imagick.Initialize()
defer imagick.Terminate()

mw := imagick.NewMagickWand()
mw.SetSize(300,300)

fc := imagick.NewPixelWand()
fc.SetColor("none")
mw.NewImage(300, 300, fc)
mw.SetImageArtifact("gradient:angle", "35")

mw.GradientImage(imagick.GRADIENT_TYPE_LINEAR, imagick.SPREAD_METHOD_PAD, "#ff0000", "#0000ff")

mw.WriteImage("out.png")

}
14 changes: 14 additions & 0 deletions imagick/gradient_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package imagick

/*
#include <wand/MagickWand.h>
*/
import "C"

type GradientType int

const (
GRADIENT_TYPE_UNDEFINED GradientType = C.UndefinedGradient
GRADIENT_TYPE_LINEAR GradientType = C.LinearGradient
GRADIENT_TYPE_RADIAL GradientType = C.RadialGradient
)
17 changes: 17 additions & 0 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,23 @@ func (mw *MagickWand) GetImageTotalInkDensity() float64 {
return ret
}

func (mw *MagickWand) GradientImage(gradientType GradientType, spreadMethod SpreadMethod, startColor string, stopColor string) error {
ppStart := C.PixelPacket{}
ppStop := C.PixelPacket{}

pw := NewPixelWand()
defer pw.Destroy()
pw.SetColor(startColor)
C.SetPixelViaMagickPixel(mw.GetImageFromMagickWand().img, pw.GetMagickColor().mpp, &ppStart)
pw.SetColor(stopColor)
C.SetPixelViaMagickPixel(mw.GetImageFromMagickWand().img, pw.GetMagickColor().mpp, &ppStop)
ok := C.GradientImage(mw.GetImageFromMagickWand().img,
C.GradientType(gradientType), C.SpreadMethod(spreadMethod),
&ppStart, &ppStop)
runtime.KeepAlive(mw)
return mw.getLastErrorIfFailed(ok)
}

// Replaces colors in the image from a Hald color lookup table. A Hald color
// lookup table is a 3-dimensional color cube mapped to 2 dimensions. Create
// it with the HALD coder. You can apply any color transformation to the Hald
Expand Down
15 changes: 15 additions & 0 deletions imagick/spread_method.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package imagick

/*
#include <wand/MagickWand.h>
*/
import "C"

type SpreadMethod int

const (
SPREAD_METHOD_UNDEFINED SpreadMethod = C.UndefinedGradient
SPREAD_METHOD_PAD SpreadMethod = C.PadSpread
SPREAD_METHOD_REFLECT SpreadMethod = C.ReflectSpread
SPREAD_METHOD_REPEAT SpreadMethod = C.RepeatSpread
)

0 comments on commit 93aac8e

Please sign in to comment.