Moved image resize functionality into image_manip
This commit is contained in:
parent
444a435402
commit
3745d24321
|
@ -1,3 +1,3 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
var ImageDir = "images/"
|
var ImageDir = "images/"
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/oliamb/cutter"
|
|
||||||
"image"
|
"image"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/nfnt/resize"
|
||||||
|
"github.com/oliamb/cutter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cropImage(img image.Image) image.Image {
|
func cropImage(img image.Image) image.Image {
|
||||||
|
@ -27,6 +29,10 @@ func cropImage(img image.Image) image.Image {
|
||||||
return croppedImg
|
return croppedImg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resizeSquareImage(size uint, img image.Image) image.Image {
|
||||||
|
return resize.Resize(size, 0, img, resize.Bilinear)
|
||||||
|
}
|
||||||
|
|
||||||
func circleCropImage(img image.Image, size int) image.Image {
|
func circleCropImage(img image.Image, size int) image.Image {
|
||||||
dst := image.NewRGBA(image.Rect(0, 0, size, size))
|
dst := image.NewRGBA(image.Rect(0, 0, size, size))
|
||||||
draw.DrawMask(
|
draw.DrawMask(
|
||||||
|
|
6
main.go
6
main.go
|
@ -1,9 +1,5 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/nfnt/resize"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
images = []string{
|
images = []string{
|
||||||
"elephant",
|
"elephant",
|
||||||
|
@ -33,7 +29,7 @@ func main() {
|
||||||
for _, size := range sizes {
|
for _, size := range sizes {
|
||||||
for i := 1; i < 11; i++ {
|
for i := 1; i < 11; i++ {
|
||||||
|
|
||||||
ri := resize.Resize(size, 0, croppedImg, resize.Bilinear)
|
ri := resizeSquareImage(size, croppedImg)
|
||||||
id := makeImageDetails(imageName, size, i*10, "")
|
id := makeImageDetails(imageName, size, i*10, "")
|
||||||
outputImage(ri, &id)
|
outputImage(ri, &id)
|
||||||
imgDs[imageName] = append(imgDs[imageName], id)
|
imgDs[imageName] = append(imgDs[imageName], id)
|
||||||
|
|
Loading…
Reference in New Issue