Skip to content

Instantly share code, notes, and snippets.

@teepark
Created March 18, 2015 20:33
Show Gist options
  • Save teepark/21fbbb1f1162442dae4a to your computer and use it in GitHub Desktop.
Save teepark/21fbbb1f1162442dae4a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"image"
"image/jpeg"
"os"
"github.com/nfnt/resize"
"github.com/oliamb/cutter"
)
func main() {
rdr, err := os.Open("profile.jpg")
if err != nil {
fmt.Printf("open: %v\n", err)
return
}
img, _, err := image.Decode(rdr)
if err != nil {
fmt.Printf("decode: %v\n", err)
return
}
wr, err := os.OpenFile("smallprofile.jpg", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
fmt.Printf("openfile: %v\n", err)
return
}
img, err = cutter.Crop(img, cutter.Config{
Width: 760,
Height: 760,
Anchor: image.Point{X: 100, Y: 100},
})
if err != nil {
fmt.Printf("crop: %v\n", err)
return
}
img = resize.Resize(380, 380, img, resize.Bicubic)
err = jpeg.Encode(wr, img, &jpeg.Options{96})
if err != nil {
fmt.Printf("jpeg.encode: %v\n", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment