本文整理汇总了Golang中image.Bounds函数的典型用法代码示例。如果您正苦于以下问题:Golang Bounds函数的具体用法?Golang Bounds怎么用?Golang Bounds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Bounds函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestResizeImage

func (s *ResizeSuite) TestResizeImage(c *C) {
    file, err := ioutil.ReadFile("test/exif_test_img.jpg")
    c.Assert(err, IsNil)

    for width, height := range sizes {
        ctx := &fetch.CacheContext{
            Width: width,
        }

        data := bytes.NewBuffer(file)

        orig, _, err := fetch.GetRotatedImage(data)
        c.Check(err, IsNil)

        buf := new(bytes.Buffer)
        jpeg.Encode(buf, orig, nil)

        resized, err := fetch.Resize(buf, ctx)
        c.Check(err, IsNil)

        image, _, err := image.Decode(resized)
        c.Check(err, IsNil)
        c.Check(image.Bounds().Size().X, Equals, width)
        c.Check(image.Bounds().Size().Y, Equals, height)
    }
}

开发者ID:danrjohnson,项目名称:media-proxy,代码行数:26,代码来源:resize_test.go

示例2: TestResizeImageSquare

func (s *ResizeSuite) TestResizeImageSquare(c *C) {
    file, err := ioutil.ReadFile("test/awesome.jpeg")
    c.Assert(err, IsNil)

    for width, _ := range sizes {
        ctx := &fetch.CacheContext{
            Width: width,
            Crop:  true,
        }

        buf := bytes.NewReader(file)
        resized, err := fetch.Resize(buf, ctx)
        c.Check(err, IsNil)

        image, _, err := image.Decode(resized)
        c.Check(err, IsNil)

        if width > 768 {
            width = 768
        }

        c.Check(image.Bounds().Size().X, Equals, width)
        c.Check(image.Bounds().Size().Y, Equals, width)
    }
}

开发者ID:danrjohnson,项目名称:media-proxy,代码行数:25,代码来源:resize_test.go

示例3: ReadBinary

func ReadBinary(tbl [][]byte, name string) (r string) {
    image := GetPngData(name)
    gw := image.Bounds().Max.X
    gh := image.Bounds().Max.Y
    for y := 12; y < gh-H; y += 22 {
        for x := 9; x < gw-W; x += 36 {
            s0 := SplitImage(image, W, H, x, y)
            if IsOne(s0) {
                continue
            }
            a := FindNum(tbl, s0)
            s1 := SplitImage(image, W, H, x+12, y)
            b := FindNum(tbl, s1)
            if a < 0 || b < 0 {
                fmt.Println("bad char", name, x, y, len(r))
                fmt.Println("a", a)
                PutPattern(s0, W)
                fmt.Println("b", b)
                PutPattern(s1, W)
                os.Exit(1)
            }
            v := a*16 + b
            r = r + fmt.Sprintf("%02x", v)
        }
    }
    if len(r) != 62 {
        fmt.Println("bad byte", name, len(r))
        fmt.Println(r)
        os.Exit(1)
    }
    return
}

开发者ID:herumi,项目名称:misc,代码行数:32,代码来源:dec_jpg.go

示例4: save

func (s _Sprite) save(spriteImg image.Image, items []_ImageItem, fullWidth, fullHeight int) error {
    targetFolder := fmt.Sprintf("public/images/%s", s.entry)
    target := path.Join(targetFolder, s.name+".png")
    if file, err := os.Create(target); err != nil {
        return fmt.Errorf("Cannot create sprite file %s, %v", target, err)
    } else {
        defer file.Close()
        if err := png.Encode(file, spriteImg); err != nil {
            return nil
        }
        target = s.addFingerPrint(targetFolder, s.name+".png")
        loggers.Succ("[Sprite][%s] Saved sprite image: %s", s.entry, target)

        // generate the stylus file
        stylus := "assets/stylesheets/sprites"
        if err := os.MkdirAll(stylus, os.ModePerm|os.ModeDir); err != nil {
            return fmt.Errorf("Cannot mkdir %s, %v", stylus, err)
        }
        stylus = fmt.Sprintf("assets/stylesheets/sprites/%s_%s.styl", s.entry, s.name)
        if stylusFile, err := os.Create(stylus); err != nil {
            return fmt.Errorf("Cannot create the stylus file for sprite %s, %v", stylus, err)
        } else {
            defer stylusFile.Close()

            spriteEntry := SpriteEntry{
                Entry:   s.entry,
                Name:    s.name,
                Url:     fmt.Sprintf("%s/images/%s/%s", s.config.UrlPrefix, s.entry, filepath.Base(target)),
                Sprites: make([]SpriteImage, len(items)),
                Width:   fullWidth / s.pixelRatio,
                Height:  fullHeight / s.pixelRatio,
            }
            lastHeight := 0
            for i, image := range items {
                name := image.name
                name = name[:len(name)-len(filepath.Ext(name))]
                width, height := image.Bounds().Dx(), image.Bounds().Dy()
                if width%s.pixelRatio != 0 || height%s.pixelRatio != 0 {
                    loggers.Warn("You have images cannot be adjusted by the pixel ratio, %s, bounds=%v, pixelRatio=%d",
                        image.fullpath, image.Bounds(), s.pixelRatio)
                }
                spriteEntry.Sprites[i] = SpriteImage{
                    Name:   fmt.Sprintf("%s-%s", s.name, name),
                    X:      0,
                    Y:      -1 * lastHeight,
                    Width:  width / s.pixelRatio,
                    Height: height / s.pixelRatio,
                }
                lastHeight += (height + s.pixelRatio) / s.pixelRatio
            }
            if err := tmSprites.Execute(stylusFile, spriteEntry); err != nil {
                return fmt.Errorf("Cannot generate stylus for sprites %s, %v", spriteEntry, err)
            }
        }
    }
    return nil
}

开发者ID:changshaopeng,项目名称:gobuildweb,代码行数:57,代码来源:sprite.go

示例5: TestPreviewPdf

func (s *ResizeSuite) TestPreviewPdf(c *C) {
    file, err := ioutil.ReadFile("test/trunq_sprint_7-1.pdf")
    c.Assert(err, IsNil)

    buf := bytes.NewReader(file)

    preview, err := getPdfPreview(buf)
    c.Check(err, IsNil)

    previewBuf := bytes.NewReader(preview)

    image, _, err := image.Decode(previewBuf)
    c.Check(err, IsNil)
    c.Check(image.Bounds().Size().X, Equals, 1650)
    c.Check(image.Bounds().Size().Y, Equals, 1275)
}

开发者ID:danrjohnson,项目名称:media-proxy,代码行数:16,代码来源:resize_test.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng