forked from rainycape/magick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize.go
77 lines (66 loc) · 2.71 KB
/
resize.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package magick
// #include <magick/api.h>
// #include "bridge.h"
// #include "resize.h"
import "C"
type Filter C.FilterTypes
const (
FPoint Filter = C.PointFilter
FBox Filter = C.BoxFilter
FTriangle Filter = C.TriangleFilter
FHermite Filter = C.HermiteFilter
FHanning Filter = C.HanningFilter
FHamming Filter = C.HammingFilter
FBlackman Filter = C.BlackmanFilter
FGaussian Filter = C.GaussianFilter
FQuadratic Filter = C.QuadraticFilter
FCubic Filter = C.CubicFilter
FCatrom Filter = C.CatromFilter
FMitchell Filter = C.MitchellFilter
FLanczos Filter = C.LanczosFilter
FBessel Filter = C.BesselFilter
FSinc Filter = C.SincFilter
)
// Magnify is a convenience method that scales an image proportionally to twice its size.
func (im *Image) Magnify() (*Image, error) {
return im.applyFunc("magnifying", C.ImageFunc(C.MagnifyImage))
}
// Minify is a convenience method that scales an image proportionally to half its size.
func (im *Image) Minify() (*Image, error) {
return im.applyFunc("minifying", C.ImageFunc(C.MinifyImage))
}
// ResizeBlur returns a new image resized to the given dimensions using the provided
// filter and blur factor (where > 1 is blurry, < 1 is sharp).
func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) {
var data C.ResizeData
data.columns = C.ulong(width)
data.rows = C.ulong(height)
data.filter = C.FilterTypes(filter)
data.blur = C.double(blur)
return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data)
}
// Resize works like ResizeBlur, but sets the blur to 1
func (im *Image) Resize(width, height int, filter Filter) (*Image, error) {
return im.ResizeBlur(width, height, filter, 1)
}
func (im *Image) sizeFunc(what string, width, height int, f C.ImageDataFunc) (*Image, error) {
var s C.SizeData
s.columns = C.ulong(width)
s.rows = C.ulong(height)
return im.applyDataFunc(what, f, &s)
}
// Sample scales an image to the desired dimensions with pixel sampling.
// Unlike other scaling methods, this method does not introduce any
// additional color into the scaled image.
func (im *Image) Sample(width, height int) (*Image, error) {
return im.sizeFunc("sampling", width, height, C.ImageDataFunc(C.sampleImage))
}
// Scale changes the size of an image to the given dimensions.
func (im *Image) Scale(width, height int) (*Image, error) {
return im.sizeFunc("scaling", width, height, C.ImageDataFunc(C.scaleImage))
}
// Thumbnail changes the size of an image to the given dimensions. This
// method was designed by Bob Friesenhahn as a low cost thumbnail generator.
func (im *Image) Thumbnail(width, height int) (*Image, error) {
return im.sizeFunc("thumbnailing", width, height, C.ImageDataFunc(C.thumbnailImage))
}