-
Notifications
You must be signed in to change notification settings - Fork 1
/
seam.go
32 lines (30 loc) · 838 Bytes
/
seam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package seam
import (
"bytes"
"fmt"
"github.com/esimov/caire"
"github.com/pkg/errors"
"net/http"
)
func ContentAwareResize(url string) ([]byte, error) {
fmt.Printf("Download starting for url %s \n", url)
response, err := http.Get(url)
if err != nil {
return nil, errors.Wrap(err, "Failed to read the image")
}
defer response.Body.Close()
converted := &bytes.Buffer{}
fmt.Printf("Download complete %s \n", url)
shrinkFactor := 30
fmt.Printf("Resize in progress %s, shrinking width by %d percent... \n", url, shrinkFactor)
p := &caire.Processor{
NewWidth: shrinkFactor,
Percentage: true,
}
err = p.Process(response.Body, converted)
if err != nil {
return nil, errors.Wrap(err, "Failed to apply seam carving to the image")
}
fmt.Printf("Seam carving completed for %s \n", url)
return converted.Bytes(), nil
}