Created
April 5, 2018 05:30
-
-
Save j4cksw/0d47447cde2a9bc36a4fe3d4f82a04a0 to your computer and use it in GitHub Desktop.
# install imageMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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