Skip to content

Instantly share code, notes, and snippets.

@j4cksw
Created April 5, 2018 05:30
Show Gist options
  • Select an option

  • Save j4cksw/0d47447cde2a9bc36a4fe3d4f82a04a0 to your computer and use it in GitHub Desktop.

Select an option

Save j4cksw/0d47447cde2a9bc36a4fe3d4f82a04a0 to your computer and use it in GitHub Desktop.
# install imageMagick
package main
import (
"fmt"
"github.com/jung-kurt/gofpdf"
"gopkg.in/gographics/imagick.v3/imagick"
)
func main() {
Example()
}
func Example() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello, world")
err := pdf.OutputFileAndClose("hello.pdf")
if err != nil {
fmt.Println(err)
}
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer func() {
mw.Clear()
mw.Destroy()
}()
pw := imagick.NewPixelWand()
pw.SetColor("white")
mw.SetBackgroundColor(pw)
readErr := mw.ReadImage("hello.pdf")
if readErr != nil {
fmt.Println(readErr)
}
bg := imagick.NewMagickWand()
x, y, _ := mw.GetImageResolution()
bg.SetResolution(x, y)
bg.NewImage(mw.GetImageWidth(), mw.GetImageHeight(), pw)
bg.CompositeImage(mw, imagick.COMPOSITE_OP_OVER, false, 0, 0)
bg.SetImageFormat("jpg")
bg.ResizeImage(1040, 1040, imagick.FILTER_BOX)
writeErr := bg.WriteImage("hello.jpg")
if writeErr != nil {
fmt.Println(writeErr)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment