本文整理汇总了Golang中github.com/disintegration/imaging.FlipV函数的典型用法代码示例。如果您正苦于以下问题:Golang FlipV函数的具体用法?Golang FlipV怎么用?Golang FlipV使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FlipV函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CaptureToPng
func CaptureToPng(filename string) error {
// Based on a version from https://github.com/go-gl/glh.
// Copyright (c) 2012 The go-gl Authors. All rights reserved.
w, h := glh.GetViewportWH()
im := image.NewNRGBA(image.Rect(0, 0, w, h))
gl.ReadBuffer(gl.BACK_LEFT)
gl.ReadPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, im.Pix)
// Flip the image vertically.
//
// From IRC:
// <ClaudiusMaximus> nictuku: glReadPixels uses (0,0) at bottom left always
// - some (most?) image formats use (0,0) as top left
im = imaging.FlipV(im)
fd, err := os.Create(filename)
if err != nil {
return err
}
defer fd.Close()
png.Encode(fd, im)
return nil
}
开发者ID:nictuku,项目名称:chip-8,代码行数:26,代码来源:video.go
示例2: transformImage
// transformImage modifies the image m based on the transformations specified
// in opt.
func transformImage(m image.Image, opt Options) image.Image {
// resize if needed
if w, h, resize := resizeParams(m, opt); resize {
if opt.Fit {
m = imaging.Fit(m, w, h, resampleFilter)
} else {
if w == 0 || h == 0 {
m = imaging.Resize(m, w, h, resampleFilter)
} else {
m = imaging.Thumbnail(m, w, h, resampleFilter)
}
}
}
// flip
if opt.FlipVertical {
m = imaging.FlipV(m)
}
if opt.FlipHorizontal {
m = imaging.FlipH(m)
}
// rotate
switch opt.Rotate {
case 90:
m = imaging.Rotate90(m)
case 180:
m = imaging.Rotate180(m)
case 270:
m = imaging.Rotate270(m)
}
return m
}
开发者ID:LimiQS,项目名称:imageproxy,代码行数:36,代码来源:transform.go
示例3: DecodeImage
func DecodeImage(data io.Reader) (image.Image, error) {
img, _, err := image.Decode(data)
if err != nil {
fmt.Printf("Error decoding geometry file: %v\n", err)
return nil, err
}
img = imaging.FlipV(img)
return img, nil
}
开发者ID:walesey,项目名称:go-engine,代码行数:9,代码来源:importers.go
示例4: updateImage
func (te *TextElement) updateImage(size mgl32.Vec2) {
// Initialize the context.
bg := image.Transparent
c := te.getContext()
text := te.GetHiddenText()
if len(text) == 0 {
text = te.props.placeholder
r, g, b, _ := te.props.textColor.RGBA()
placeholderColor := color.RGBA{uint8(r), uint8(g), uint8(b), 80}
c.SetSrc(image.NewUniform(placeholderColor))
}
// Establish image dimensions and do word wrap
textHeight := c.PointToFixed(float64(te.props.textSize))
var width int
var height int = int(textHeight >> 6)
words := strings.Split(text, " ")
lines := []string{""}
lineNb := 0
for _, word := range words {
wordWithSpace := fmt.Sprintf("%v ", word)
dimensions, _ := c.StringDimensions(wordWithSpace)
width += int(dimensions.X >> 6)
if width > int(size.X()) {
width = int(dimensions.X >> 6)
height += int(dimensions.Y>>6) + 1
lines = append(lines, "")
lineNb += 1
}
lines[lineNb] = fmt.Sprintf("%v%v", lines[lineNb], wordWithSpace)
}
if te.props.height > 0 {
height = int(te.props.height)
}
rgba := image.NewRGBA(image.Rect(0, 0, int(size.X()), height+int(textHeight>>6)/3))
draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)
c.SetClip(rgba.Bounds())
c.SetDst(rgba)
// Draw the text.
pt := freetype.Pt(0, int(textHeight>>6))
for _, line := range lines {
_, err := c.DrawString(line, pt)
if err != nil {
log.Printf("Error drawing string: %v\n", err)
return
}
pt.Y += textHeight
}
te.img.SetImage(imaging.FlipV(rgba))
te.img.SetWidth(float32(rgba.Bounds().Size().X))
te.img.SetHeight(float32(rgba.Bounds().Size().Y))
}
开发者ID:walesey,项目名称:go-engine,代码行数:56,代码来源:text.go
示例5: loadCubeMap
func (glRenderer *OpenglRenderer) loadCubeMap(right, left, top, bottom, back, front image.Image, textureUnit uint32, lod bool) uint32 {
var texId uint32
gl.GenTextures(1, &texId)
gl.ActiveTexture(textureUnit)
gl.BindTexture(gl.TEXTURE_CUBE_MAP, texId)
for i := 0; i < 6; i++ {
img := right
var texIndex uint32 = gl.TEXTURE_CUBE_MAP_POSITIVE_X
switch i {
case 1:
img = left
texIndex = gl.TEXTURE_CUBE_MAP_NEGATIVE_X
case 2:
img = top
texIndex = gl.TEXTURE_CUBE_MAP_NEGATIVE_Y
case 3:
img = bottom
texIndex = gl.TEXTURE_CUBE_MAP_POSITIVE_Y
case 4:
img = back
texIndex = gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
case 5:
img = front
texIndex = gl.TEXTURE_CUBE_MAP_POSITIVE_Z
}
img = imaging.FlipV(img)
rgba := image.NewRGBA(img.Bounds())
if rgba.Stride != rgba.Rect.Size().X*4 {
log.Fatal("unsupported stride")
}
draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, draw.Src)
gl.TexImage2D(
texIndex,
0,
gl.RGBA,
int32(rgba.Rect.Size().X),
int32(rgba.Rect.Size().Y),
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
gl.Ptr(rgba.Pix),
)
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE)
if lod {
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
gl.GenerateMipmap(gl.TEXTURE_CUBE_MAP)
} else {
gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
}
}
return texId
}
开发者ID:walesey,项目名称:go-engine,代码行数:56,代码来源:glRenderer.go
示例6: rotate
func rotate(img image.Image, orientation int) image.Image {
fmt.Println("orientation:", orientation)
// 1 2 3 4 5 6 7 8
// 888888 888888 88 88 8888888888 88 88 8888888888
// 88 88 88 88 88 88 88 88 88 88 88 88
// 8888 8888 8888 8888 88 8888888888 8888888888 88
// 88 88 88 88
// 88 88 888888 888888
// func Rotate180(img image.Image) *image.NRGBA
// func Rotate270(img image.Image) *image.NRGBA
// func Rotate90(img image.Image) *image.NRGBA
// func FlipH(img image.Image) *image.NRGBA
// func FlipV(img image.Image) *image.NRGBA
var out image.Image
switch orientation {
case 1:
out = img
// nothing;
case 2:
out = imaging.FlipH(img)
// flip Horiz L to R
case 3:
out = imaging.Rotate180(img)
// rotate 180 ccw
case 4:
out = imaging.FlipV(img)
// flip Vert T to B
case 5:
out = imaging.Transpose(img)
// transpose
case 6:
out = imaging.Rotate90(img)
// rotate 90
case 7:
out = imaging.Transverse(img)
// transverse
case 8:
out = imaging.Rotate270(img)
// rotate 270
default:
out = img
// nothing;
}
return out
}
开发者ID:zqzca,项目名称:back,代码行数:49,代码来源:thumbnail.go
示例7: handleImages
func handleImages(previewPathList []string, thumbnailPathList []string, fileData [][]byte) {
for i, data := range fileData {
go func(i int, data []byte) {
// Decode image bytes into Image object
img, imgType, err := image.Decode(bytes.NewReader(fileData[i]))
if err != nil {
l4g.Error(utils.T("api.file.handle_images_forget.decode.error"), err)
return
}
width := img.Bounds().Dx()
height := img.Bounds().Dy()
// Fill in the background of a potentially-transparent png file as white
if imgType == "png" {
dst := image.NewRGBA(img.Bounds())
draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
img = dst
}
// Flip the image to be upright
orientation, _ := getImageOrientation(fileData[i])
switch orientation {
case UprightMirrored:
img = imaging.FlipH(img)
case UpsideDown:
img = imaging.Rotate180(img)
case UpsideDownMirrored:
img = imaging.FlipV(img)
case RotatedCWMirrored:
img = imaging.Transpose(img)
case RotatedCCW:
img = imaging.Rotate270(img)
case RotatedCCWMirrored:
img = imaging.Transverse(img)
case RotatedCW:
img = imaging.Rotate90(img)
}
go generateThumbnailImage(img, thumbnailPathList[i], width, height)
go generatePreviewImage(img, previewPathList[i], width)
}(i, data)
}
}
开发者ID:duzhanyuan,项目名称:platform,代码行数:46,代码来源:file.go
示例8: prepareImage
func prepareImage(fileData []byte) (*image.Image, int, int) {
// Decode image bytes into Image object
img, imgType, err := image.Decode(bytes.NewReader(fileData))
if err != nil {
l4g.Error(utils.T("api.file.handle_images_forget.decode.error"), err)
return nil, 0, 0
}
width := img.Bounds().Dx()
height := img.Bounds().Dy()
// Fill in the background of a potentially-transparent png file as white
if imgType == "png" {
dst := image.NewRGBA(img.Bounds())
draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
img = dst
}
// Flip the image to be upright
orientation, _ := getImageOrientation(fileData)
switch orientation {
case UprightMirrored:
img = imaging.FlipH(img)
case UpsideDown:
img = imaging.Rotate180(img)
case UpsideDownMirrored:
img = imaging.FlipV(img)
case RotatedCWMirrored:
img = imaging.Transpose(img)
case RotatedCCW:
img = imaging.Rotate270(img)
case RotatedCCWMirrored:
img = imaging.Transverse(img)
case RotatedCW:
img = imaging.Rotate90(img)
}
return &img, width, height
}
开发者ID:Rudloff,项目名称:platform,代码行数:41,代码来源:file.go
示例9: TransformImage
// Transforms image (resize, rotate, flip, brightness, contrast)
func (c *Convertor) TransformImage(img image.Image) image.Image {
var i image.Image = img
if c.Opts.Width > 0 || c.Opts.Height > 0 {
if c.Opts.Fit {
i = imaging.Fit(i, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
} else {
i = imaging.Resize(i, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
}
}
if c.Opts.Rotate > 0 {
switch c.Opts.Rotate {
case 90:
i = imaging.Rotate90(i)
case 180:
i = imaging.Rotate180(i)
case 270:
i = imaging.Rotate270(i)
}
}
if c.Opts.Flip != "none" {
switch c.Opts.Flip {
case "horizontal":
i = imaging.FlipH(i)
case "vertical":
i = imaging.FlipV(i)
}
}
if c.Opts.Brightness != 0 {
i = imaging.AdjustBrightness(i, c.Opts.Brightness)
}
if c.Opts.Contrast != 0 {
i = imaging.AdjustContrast(i, c.Opts.Contrast)
}
return i
}
开发者ID:gen2brain,项目名称:cbconvert,代码行数:42,代码来源:cbconvert.go
示例10: loadTextureFromFile
func (self *TextureManager) loadTextureFromFile(texturePath string, isMagenta, forceMaxResolution bool) (*image.NRGBA, error) {
textureFile, err := os.Open(texturePath)
if err != nil {
return nil, err
}
defer textureFile.Close()
img, err := png.Decode(textureFile)
if err != nil {
return nil, err
}
//Bild für OpenGL drehen
texture := imaging.FlipV(img)
if !forceMaxResolution {
//es soll nicht die max. Texturauflösung verwendet werden --> Bild entsprechend halbieren
for res := 5 - self.resolution; res > 0; res-- {
size := texture.Bounds().Size()
texture = imaging.Resize(texture, size.X/2, size.Y/2, imaging.Linear)
}
}
if isMagenta {
convertImageToAlpha(texture)
}
return texture, nil
}
开发者ID:abieberbach,项目名称:goplanemp,代码行数:24,代码来源:TextureManager.go
示例11: storeImage
//.........这里部分代码省略.........
bucketHandle = client.Bucket(bucketName)
c.Infof("APP Engine Version: %s", gcsappengine.VersionID(cc))
c.Infof("Using bucket name: %s", bucketName)
// Change default object ACLs
if err = bucketHandle.DefaultObjectACL().Set(cc, storage.AllUsers, storage.RoleReader); err != nil {
c.Errorf("%v in saving default object ACL rule for bucket %q", err, bucketName)
r = http.StatusInternalServerError
return
}
// Store rotated image in Google Cloud Storage
var in *bytes.Reader = bytes.NewReader(b)
var x *exif.Exif = nil
var orientation *tiff.Tag = nil
var beforeImage image.Image
var afterImage *image.NRGBA = nil
// Read EXIF
if _, err = in.Seek(0, 0); err != nil {
c.Errorf("%s in moving the reader offset to the beginning in order to read EXIF", err)
return
}
if x, err = exif.Decode(in); err != nil {
c.Errorf("%s in decoding JPEG image", err)
return
}
// Get Orientation
if orientation, err = x.Get(exif.Orientation); err != nil {
c.Warningf("%s in getting orientation from EXIF", err)
return
}
c.Debugf("Orientation %s", orientation.String())
// Open image
if _, err = in.Seek(0, 0); err != nil {
c.Errorf("%s in moving the reader offset to the beginning in order to read EXIF", err)
return
}
if beforeImage, err = imaging.Decode(in); err != nil {
c.Errorf("%s in opening image %s", err)
return
}
switch orientation.String() {
case "1":
afterImage = beforeImage.(*image.NRGBA)
case "2":
afterImage = imaging.FlipH(beforeImage)
case "3":
afterImage = imaging.Rotate180(beforeImage)
case "4":
afterImage = imaging.FlipV(beforeImage)
case "5":
afterImage = imaging.Transverse(beforeImage)
case "6":
afterImage = imaging.Rotate270(beforeImage)
case "7":
afterImage = imaging.Transpose(beforeImage)
case "8":
afterImage = imaging.Rotate90(beforeImage)
}
// Save rotated image
wc = bucketHandle.Object(fileName).NewWriter(cc)
wc.ContentType = contentType
if err = imaging.Encode(wc, afterImage, imaging.JPEG); err != nil {
c.Errorf("%s in saving rotated image", err)
return
}
if err = wc.Close(); err != nil {
c.Errorf("CreateFile: unable to close bucket %q, file %q: %v", bucketName, fileName, err)
r = 1
return
}
wc = nil
// Make thumbnail
if afterImage.Rect.Dx() > afterImage.Rect.Dy() {
afterImage = imaging.Resize(afterImage, 1920, 0, imaging.Lanczos)
} else {
afterImage = imaging.Resize(afterImage, 0, 1920, imaging.Lanczos)
}
// Save thumbnail
wc = bucketHandle.Object(fileNameThumbnail).NewWriter(cc)
wc.ContentType = contentType
if imaging.Encode(wc, afterImage, imaging.JPEG); err != nil {
c.Errorf("%s in saving image thumbnail", err)
return
}
if err = wc.Close(); err != nil {
c.Errorf("CreateFileThumbnail: unable to close bucket %q, file %q: %v", bucketName, fileNameThumbnail, err)
r = 1
return
}
c.Infof("/%v/%v, /%v/%v created", bucketName, fileName, bucketName, fileNameThumbnail)
}
开发者ID:junglesung,项目名称:Aliza,代码行数:101,代码来源:images.go
示例12: transformImage
// transformImage modifies the image m based on the transformations specified
// in opt.
func transformImage(m image.Image, opt Options) image.Image {
// convert percentage width and height values to absolute values
imgW := m.Bounds().Max.X - m.Bounds().Min.X
imgH := m.Bounds().Max.Y - m.Bounds().Min.Y
var w, h int
if 0 < opt.Width && opt.Width < 1 {
w = int(float64(imgW) * opt.Width)
} else if opt.Width < 0 {
w = 0
} else {
w = int(opt.Width)
}
if 0 < opt.Height && opt.Height < 1 {
h = int(float64(imgH) * opt.Height)
} else if opt.Height < 0 {
h = 0
} else {
h = int(opt.Height)
}
// never resize larger than the original image
if !opt.ScaleUp {
if w > imgW {
w = imgW
}
if h > imgH {
h = imgH
}
}
// resize
if w != 0 || h != 0 {
if opt.Fit {
m = imaging.Fit(m, w, h, resampleFilter)
} else {
if w == 0 || h == 0 {
m = imaging.Resize(m, w, h, resampleFilter)
} else {
m = imaging.Thumbnail(m, w, h, resampleFilter)
}
}
}
// flip
if opt.FlipVertical {
m = imaging.FlipV(m)
}
if opt.FlipHorizontal {
m = imaging.FlipH(m)
}
// rotate
switch opt.Rotate {
case 90:
m = imaging.Rotate90(m)
case 180:
m = imaging.Rotate180(m)
case 270:
m = imaging.Rotate270(m)
}
return m
}
开发者ID:victortrac,项目名称:imageproxy,代码行数:65,代码来源:transform.go
示例13: FlipVertical
func (i imagingFlipper) FlipVertical(tile image.Image) image.Image {
return imaging.FlipV(tile)
}
开发者ID:manyminds,项目名称:tmx,代码行数:3,代码来源:flipper.go
示例14: main
func main() {
fmt.Println("Hello, world")
fname := "P1070332.JPG"
rname := "P1070332_rotate.JPG"
sname := "P1070332_small.JPG"
f, err := os.Open(fname)
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Optionally register camera makenote data parsing - currently Nikon and
// Canon are supported.
exif.RegisterParsers(mknote.All...)
x, err := exif.Decode(f)
if err != nil {
log.Fatal(err)
}
// Get Orientation
orientation, err := x.Get(exif.Orientation)
if err != nil {
fmt.Println(exif.Model, " not fround")
return
}
fmt.Println("Orientation", orientation.String())
// Rotate
var rotateImage *image.NRGBA
openImage, err := imaging.Open(fname)
if err != nil {
fmt.Println(err)
return
}
switch orientation.String() {
case "1":
// Do nothing
case "2":
rotateImage = imaging.FlipH(openImage)
case "3":
rotateImage = imaging.Rotate180(openImage)
case "4":
rotateImage = imaging.FlipV(openImage)
case "5":
rotateImage = imaging.Transverse(openImage)
case "6":
rotateImage = imaging.Rotate270(openImage)
case "7":
rotateImage = imaging.Transpose(openImage)
case "8":
rotateImage = imaging.Rotate90(openImage)
}
err = imaging.Save(rotateImage, rname)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(rname, " saved")
// Small
var smallImage *image.NRGBA
if rotateImage.Rect.Dx() > rotateImage.Rect.Dy() {
smallImage = imaging.Resize(rotateImage, 1920, 0, imaging.Lanczos)
} else {
smallImage = imaging.Resize(rotateImage, 0, 1920, imaging.Lanczos)
}
err = imaging.Save(smallImage, sname)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(sname, " saved")
// Use jpeg.Encode() to write to a file
// https://github.com/disintegration/imaging/blob/master/helpers.go#L79
// func Encode(w io.Writer, m image.Image, o *Options) error
// https://golang.org/pkg/image/jpeg/
}
开发者ID:junglesung,项目名称:TestGoRotateImage,代码行数:80,代码来源:main.go
注:本文中的github.com/disintegration/imaging.FlipV函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论