本文整理汇总了Golang中github.com/disintegration/gift.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: varianceF
func varianceF(img image.Image, disk int) (imageF, imageF) {
m := meanF(img, disk) // gets a grayscale copy of local mean
// create a grayscale version of the original
//g := gift.New( gift.Grayscale() )
//v := image.NewRGBA(g.Bounds(img.Bounds()))
//g.Draw(v, img)
g := gift.New(gift.Grayscale())
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
bounds := img.Bounds()
floatData := make([][]float32, bounds.Max.Y-bounds.Min.Y)
for i := range floatData {
floatData[i] = make([]float32, bounds.Max.X-bounds.Min.X)
}
for y := bounds.Min.X; y < bounds.Max.X; y++ {
for x := bounds.Min.Y; x < bounds.Max.Y; x++ {
p1r, p1g, p1b, _ := dst.At(x, y).RGBA()
g1 := 0.2125*float64(p1r) + 0.7154*float64(p1g) + 0.0721*float64(p1b)
g2 := float64(m[x][y])
floatData[x][y] = float32((g1 - g2) * (g1 - g2))
}
}
return m, floatData
}
开发者ID:HaukeBartsch,项目名称:talk,代码行数:28,代码来源:utils.go
示例2: makeThumb
func makeThumb(source, destination string) error { // {{{
file, err := os.Open(source)
if err != nil {
return err
}
defer file.Close()
// decode jpeg into image.Image
img, err := jpeg.Decode(file)
if err != nil {
return err
}
g := gift.New(
gift.ResizeToFill(200, 200, gift.LanczosResampling, gift.CenterAnchor),
)
out, err := os.Create(destination)
if err != nil {
return err
}
defer out.Close()
// write new image to file
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
return jpeg.Encode(out, dst, &jpeg.Options{100})
} // }}}
开发者ID:stamp,项目名称:go-dsmobile,代码行数:28,代码来源:websocket-packets.go
示例3: Render
// Render draws rune r front the specified font at the specified dpi and scale. It returns a
// grayscale image that is just large enough to contain the rune.
func Render(font *truetype.Font, r rune, dpi, scale float64) (*image.Gray, error) {
glyph := truetype.NewGlyphBuf()
index := font.Index(r)
glyph.Load(font, font.FUnitsPerEm(), index, truetype.FullHinting)
ctx := freetype.NewContext()
boxer := makeBoundingBoxer()
ctx.SetSrc(image.NewUniform(color.White))
ctx.SetDst(boxer)
ctx.SetClip(boxer.largeBounds)
ctx.SetFontSize(250)
ctx.SetDPI(dpi)
ctx.SetFont(font)
if err := glyph.Load(font, font.FUnitsPerEm(), font.Index(r), truetype.FullHinting); err != nil {
return nil, fmt.Errorf("Unable to load glyph: %v\n", err)
}
var rp raster.Point
rp.X = ctx.PointToFix32(0)
rp.Y = ctx.PointToFix32(100)
ctx.DrawString(string(r), rp)
boxer.complete()
g := gift.New(
gift.Resize(int(float64(boxer.Bounds().Dx())*scale+0.5), int(float64(boxer.Bounds().Dy())*scale+0.5), gift.CubicResampling),
)
dst := image.NewGray(g.Bounds(boxer.Bounds()))
g.Draw(dst, boxer)
return dst, nil
}
开发者ID:runningwild,项目名称:glop,代码行数:30,代码来源:glyph.go
示例4: resizeImage
// TODO Too min images should not resized
func resizeImage(src image.Image, n int) image.Image {
srcBounds := src.Bounds()
gi := gift.New(gift.Resize(srcBounds.Max.Y/n, srcBounds.Max.Y/n, gift.LanczosResampling))
dst := image.NewRGBA(gi.Bounds(srcBounds))
gi.Draw(dst, src)
return dst
}
开发者ID:gotokatsuya,项目名称:go-nudely,代码行数:8,代码来源:nudely.go
示例5: blur
func blur(img image.Image, howmuch float32) image.Image {
g := gift.New(gift.Grayscale())
g.Add(gift.GaussianBlur(howmuch))
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
return (dst)
}
开发者ID:HaukeBartsch,项目名称:talk,代码行数:7,代码来源:utils.go
示例6: createThumb
func (fi *FileInfo) createThumb(buffer *bytes.Buffer, c context.Context) {
if imageTypes.MatchString(fi.Type) {
src, _, err := image.Decode(bytes.NewReader(buffer.Bytes()))
check(err)
filter := gift.New(gift.ResizeToFit(
THUMB_MAX_WIDTH,
THUMB_MAX_HEIGHT,
gift.LanczosResampling,
))
dst := image.NewNRGBA(filter.Bounds(src.Bounds()))
filter.Draw(dst, src)
buffer.Reset()
bWriter := bufio.NewWriter(buffer)
switch fi.Type {
case "image/jpeg", "image/pjpeg":
err = jpeg.Encode(bWriter, dst, nil)
case "image/gif":
err = gif.Encode(bWriter, dst, nil)
default:
err = png.Encode(bWriter, dst)
}
check(err)
bWriter.Flush()
thumbnailKey := fi.Key + thumbSuffix + filepath.Ext(fi.Name)
item := &memcache.Item{
Key: thumbnailKey,
Value: buffer.Bytes(),
}
err = memcache.Set(c, item)
check(err)
fi.ThumbnailKey = thumbnailKey
}
}
开发者ID:hongtien510,项目名称:cakephp-routing,代码行数:33,代码来源:main.go
示例7: mean
func mean(img image.Image, disk int) image.Image {
g := gift.New(gift.Grayscale())
g.Add(gift.Mean(disk, false)) // use square neighborhood
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
return (dst)
}
开发者ID:HaukeBartsch,项目名称:talk,代码行数:7,代码来源:utils.go
示例8: DrawPicture
// DrawPicture .
func DrawPicture(src image.Image, width int, height int) *image.Gray {
rect := image.Rect(0, 0, width, height)
img := image.NewGray(rect)
rander := rander()
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
var c color.Gray
if IsBlack(src, x, y) {
if y > 1 && IsNotBlack(src, x, y-1) {
c = borderColor(rander)
} else {
c = insideColor(rander)
}
} else {
c = outsideColor(rander)
}
x1, y1 := transformCurve(x, y, width, height)
//c = color.Gray{c.Y + ScaledLuminanceAt(90, src, x, y)}
img.Set(x1, y1, c)
}
}
g := gift.New(
//gift.GaussianBlur(2),
)
img2 := image.NewGray(rect)
g.Draw(img2, img)
return img2
}
开发者ID:yarmand,项目名称:nessimage,代码行数:29,代码来源:ultrasound_generator.go
示例9: analyzeFile
func analyzeFile(filename string, resize bool) (*Cover, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
return nil, err
}
if resize {
start := time.Now()
g := gift.New(gift.Resize(500, 0, gift.LanczosResampling))
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
img = dst
fmt.Printf("- RESIZE %s took %s\n", path.Base(filename), time.Since(start))
}
start := time.Now()
bg, c1, c2, c3 := colorart.Analyze(img)
fmt.Printf("- ANALYZE %s took %s\n", path.Base(filename), time.Since(start))
return &Cover{filename, bg.String(), c1.String(), c2.String(), c3.String()}, nil
}
开发者ID:sspencer,项目名称:colorart,代码行数:29,代码来源:colors.go
示例10: procImage
func procImage(fileName string) (string, error) {
reader, err := os.Open(fileName)
if err != nil {
fmt.Errorf("Failed to open image with error: %s\n", err)
return "", err
}
defer reader.Close()
src, _, err := image.Decode(reader)
if err != nil {
fmt.Errorf("Failed to decode image with error: %s\n", err)
return "", err
}
g := gift.New(
gift.Invert(),
)
dst := image.NewRGBA(g.Bounds(src.Bounds()))
g.Draw(dst, src)
var opt jpeg.Options
opt.Quality = 100
fileName = fileName + "_processed.jpg"
out, _ := os.Create(fileName)
err = jpeg.Encode(out, dst, &opt)
if err != nil {
fmt.Errorf("Failed to encode image with error: %s\n", err)
return "", err
}
return fileName, nil
}
开发者ID:mehiar,项目名称:mesos-framework,代码行数:35,代码来源:img_utils.go
示例11: GetCube
// Sets skin.Processed to an isometric render of the head from a top-left angle (showing 3 sides).
func (skin *mcSkin) GetCube(width int) error {
// Crop out the top of the head
topFlat := imaging.Crop(skin.Image, image.Rect(8, 0, 16, 8))
// Resize appropriately, so that it fills the `width` when rotated 45 def.
topFlat = imaging.Resize(topFlat, int(float64(width)*math.Sqrt(2)/3+1), 0, imaging.NearestNeighbor)
// Create the Gift filter
filter := gift.New(
gift.Rotate(45, color.Transparent, gift.LinearInterpolation),
)
bounds := filter.Bounds(topFlat.Bounds())
top := image.NewNRGBA(bounds)
// Draw it on the filter, then smush it!
filter.Draw(top, topFlat)
top = imaging.Resize(top, width+2, width/3, imaging.NearestNeighbor)
// Skew the front and sides at 15 degree angles to match up with the
// head that has been smushed
front := skin.cropHead(skin.Image).(*image.NRGBA)
side := imaging.Crop(skin.Image, image.Rect(0, 8, 8, 16))
front = imaging.Resize(front, width/2, int(float64(width)/1.75), imaging.NearestNeighbor)
side = imaging.Resize(side, width/2, int(float64(width)/1.75), imaging.NearestNeighbor)
front = skewVertical(front, math.Pi/12)
side = skewVertical(imaging.FlipH(side), math.Pi/-12)
// Create a new image to assemble upon
skin.Processed = image.NewNRGBA(image.Rect(0, 0, width, width))
// Draw each side
draw.Draw(skin.Processed.(draw.Image), image.Rect(0, width/6, width/2, width), side, image.Pt(0, 0), draw.Src)
draw.Draw(skin.Processed.(draw.Image), image.Rect(width/2, width/6, width, width), front, image.Pt(0, 0), draw.Src)
// Draw the top we created
draw.Draw(skin.Processed.(draw.Image), image.Rect(-1, 0, width+1, width/3), top, image.Pt(0, 0), draw.Over)
return nil
}
开发者ID:spideynn,项目名称:imgd,代码行数:34,代码来源:process.go
示例12: main
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage:\tgoimger <file>")
os.Exit(1)
}
srcFileName := os.Args[1]
srcFile, _ := os.Open(srcFileName)
src, _, _ := image.Decode(srcFile)
// let's make a new gift
g := gift.New(
gift.Grayscale(),
gift.UnsharpMask(1.0, 0.5, 0.0),
)
// dest - output image
dest := image.NewRGBA(g.Bounds(src.Bounds()))
// draw result
g.Draw(dest, src)
outFileName := srcFileName + "_goimger.jpg"
toimg, _ := os.Create(outFileName)
defer toimg.Close()
jpeg.Encode(toimg, dest, &jpeg.Options{jpeg.DefaultQuality})
}
开发者ID:khangtoh,项目名称:golang-image-filtering,代码行数:28,代码来源:main.go
示例13: main
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage:\tspiffy <file>")
os.Exit(1)
}
srcFileName := os.Args[1]
srcFile, _ := os.Open(srcFileName)
src, _, _ := image.Decode(srcFile)
// 1. Create a new GIFT and add some filters:
g := gift.New(
gift.Grayscale(),
gift.UnsharpMask(1.0, 1.0, 0.0),
)
// 2. Create a new image of the corresponding size.
// dst is a new target image, src is the original image
dst := image.NewRGBA(g.Bounds(src.Bounds()))
// 3. Use Draw func to apply the filters to src and store the result in dst:
g.Draw(dst, src)
outFileName := srcFileName + ".spiffy.jpg"
toimg, _ := os.Create(outFileName)
defer toimg.Close()
jpeg.Encode(toimg, dst, &jpeg.Options{jpeg.DefaultQuality})
}
开发者ID:nixterrimus,项目名称:spiffy-gift,代码行数:29,代码来源:spiffy.go
示例14: CropImage
func CropImage(img image.Image, rect image.Rectangle) (croped image.Image) {
g := gift.New(
gift.Crop(rect),
)
croped_image := image.NewRGBA(g.Bounds(rect))
g.Draw(croped_image, img)
return croped_image
}
开发者ID:zalemwoo,项目名称:BDBKImageServer,代码行数:8,代码来源:ImageUtils.go
示例15: newResizeFuncGift
func newResizeFuncGift(resampling gift.Resampling) resizeFunc {
return func(im image.Image) image.Image {
g := gift.New(gift.Resize(width, height, resampling))
newIm := newImageFunc(g.Bounds(im.Bounds()))
g.Draw(newIm, im)
return newIm
}
}
开发者ID:pierrre,项目名称:imageresizebench,代码行数:8,代码来源:resize.go
示例16: invert
// take an image and revert its rgb channels (255-channel)
func invert(img image.Image) image.Image {
g := gift.New(gift.Grayscale(),
gift.Invert())
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
return dst
}
开发者ID:HaukeBartsch,项目名称:talk,代码行数:10,代码来源:utils.go
示例17: loadimage
// loadimage loads all the images of the deck into a map for later display
func loadimage(d deck.Deck, m map[string]image.Image) {
firstrun++
w, h := d.Canvas.Width, d.Canvas.Height
cw := openvg.VGfloat(w)
ch := openvg.VGfloat(h)
msize := int(cw * .01)
mx := cw / 2
my := ch * 0.05
mbg := "white"
mfg := "black"
for ns, s := range d.Slide {
for ni, i := range s.Image {
if !modfile(i.Name, StartTime) {
continue
}
openvg.Start(w, h)
if i.Link != "" {
fmt.Fprintf(os.Stderr, "Found altimg %s\n", i.Link)
}
f, err := os.Open(i.Name)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
continue
}
img, _, err := image.Decode(f)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
continue
}
openvg.FillColor(mbg)
openvg.Rect(0, 0, cw, ch)
openvg.FillColor(mfg)
openvg.TextMid(mx, my, fmt.Sprintf("Loading image %s %d from slide %d", i.Name, ni, ns), "sans", msize)
bounds := img.Bounds()
iw := i.Width
ih := i.Height
if i.Scale > 0 {
iw = int(float64(iw) * (i.Scale / 100))
ih = int(float64(ih) * (i.Scale / 100))
}
// if the specified dimensions are native use those, otherwise resize
if iw == (bounds.Max.X-bounds.Min.X) && ih == (bounds.Max.Y-bounds.Min.Y) {
m[i.Name] = img
} else {
g := gift.New(gift.Resize(iw, ih, gift.BoxResampling))
resized := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(resized, img)
m[i.Name] = resized
}
f.Close()
openvg.End()
}
}
}
开发者ID:Ebiroll,项目名称:openvg,代码行数:55,代码来源:xmlview.go
示例18: doit
func doit(fn string) (string, error) {
file, err := os.Open(fn)
if err != nil {
return "", err
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
return "", err
}
b := img.Bounds()
var g *gift.GIFT
if b.Max.X-b.Min.X >= resizeThreshold || b.Max.Y-b.Min.Y >= resizeThreshold {
g = gift.New(
gift.Resize(resizeSize, resizeSize, gift.LanczosResampling),
gift.GaussianBlur(sigma))
} else {
g = gift.New(gift.GaussianBlur(sigma))
}
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)
img = dst
fn = path.Base(fn)
ext := path.Ext(fn)
fn = fmt.Sprintf("./%s.blur%s", fn[:len(fn)-len(ext)], ext)
w, _ := os.Create(fn)
defer w.Close()
if err = jpeg.Encode(w, dst, nil); err != nil {
return "", err
}
return fn, nil
}
开发者ID:sspencer,项目名称:colorart,代码行数:41,代码来源:blur.go
示例19: Post
func (this *AvatarController) Post() {
w := this.ResponseWriter
r := this.Request
data := e.Data{Status: 1, Msg: "上传成功"}
log.Println("头像上传post")
r.ParseMultipartForm(32 << 20)
log.Println("表单解析")
file, handler, err := r.FormFile("realPicFile")
if err != nil {
log.Println("上传错误")
return
}
fileext := filepath.Ext(handler.Filename)
log.Println("文件后缀名字" + fileext)
if u.Check(fileext) == false {
data.Status = 0
data.Msg = "不允许的上传类型"
u.OutputJson(w, &data)
return
}
cookie := u.Cookie{HTTP: this.HTTP}
filename := cookie.GetCookie().UserId.Value + ".png"
log.Println("文件名称" + filename)
imgfile, _ := os.OpenFile(Upload_Dir+filename, os.O_CREATE|os.O_WRONLY, 0660)
defer imgfile.Close()
//把图片变成400X400尺寸的
m1, err := jpeg.Decode(file)
if err != nil {
panic(err)
}
bounds := m1.Bounds()
//如果第二参数为0则保持横纵比
g := gift.New(
gift.Resize(400, 400, gift.LanczosResampling),
)
dst := image.NewRGBA(g.Bounds(bounds))
g.Draw(dst, m1)
err = png.Encode(imgfile, dst)
if err != nil {
log.Println("上传失败")
return
}
filedir := Show_Dir + filename
data.Data = filedir
log.Println(data)
u.OutputJson(w, &data)
}
开发者ID:jjjachyty,项目名称:ibookings,代码行数:52,代码来源:Img.go
示例20: resizeImage
func resizeImage(img image.Image, size image.Point) image.Image {
g := gift.New(gift.Resize(size.X, size.Y, gift.LanczosResampling))
rect := image.Rectangle{Max: size}
switch img.(type) {
case *image.Gray:
dst := image.NewGray(rect)
g.Draw(dst, img)
return dst
default:
dst := image.NewRGBA(rect)
g.Draw(dst, img)
return dst
}
}
开发者ID:thanzen,项目名称:agostle,代码行数:14,代码来源:image.go
注:本文中的github.com/disintegration/gift.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论