Created
January 17, 2018 09:42
-
-
Save MasazI/d1861cce5c76943849e2452d53196a50 to your computer and use it in GitHub Desktop.
fit and paste golang using imaging
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 ( | |
"image/color" | |
"log" | |
"github.com/disintegration/imaging" | |
) | |
func main() { | |
srcImage, err := imaging.Open("image.jpg") | |
if err != nil { | |
log.Fatalf("Open failed: %v", err) | |
} | |
// dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos) | |
dstImageFit := imaging.Fit(srcImage, 512, 512, imaging.Lanczos) | |
err = imaging.Save(dstImageFit, "out_example_fit.jpg") | |
if err != nil { | |
log.Fatalf("Save failed: %v", err) | |
} | |
dst := imaging.New(512, 512, color.NRGBA{0, 0, 0, 0}) | |
pasteDist := imaging.PasteCenter(dst, dstImageFit) | |
err = imaging.Save(pasteDist, "out_example_paste.jpg") | |
if err != nil { | |
log.Fatalf("Save failed: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment