当前位置: 首页>>代码示例>>Golang>>正文


Golang vips.Image类代码示例

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


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

示例1: Save

// Save returns an Image compressed using the given SaveOptions as a byte slice.
func Save(image *vips.Image, options SaveOptions) ([]byte, error) {
	if options.Quality < 1 || options.Quality > 100 {
		options.Quality = DefaultQuality
	}

	if options.Compression < 1 || options.Compression > 9 {
		options.Compression = DefaultCompression
	}

	// Make a decision on image format and whether we're using lossless.
	if options.Format == Unknown {
		if options.AllowWebp {
			options.Format = Webp
		} else if image.HasAlpha() || useLossless(image, options) {
			options.Format = Png
		} else {
			options.Format = Jpeg
		}
	} else if options.Format == Webp && !useLossless(image, options) {
		options.Lossless = false
	}

	switch options.Format {
	case Jpeg:
		return jpegSave(image, options)
	case Png:
		return pngSave(image, options)
	case Webp:
		return webpSave(image, options)
	default:
		return nil, ErrInvalidSaveFormat
	}
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:34,代码来源:save.go

示例2: DetectOrientation

// DetectOrientation detects the current Image Orientation from the EXIF header.
func DetectOrientation(image *vips.Image) Orientation {
	o, ok := image.ImageGetAsString(vips.ExifOrientation)
	if !ok || o == "" {
		return Undefined
	}

	orientation, err := strconv.Atoi(o[:1])
	if err != nil || orientation <= 0 || orientation >= len(orientationInfo) {
		return Undefined
	}

	return Orientation(orientation)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:14,代码来源:orientation.go

示例3: crop

func crop(image *vips.Image, ow, oh int) error {
	m := format.MetadataImage(image)

	// If we have nothing to do, return.
	if ow == m.Width && oh == m.Height {
		return nil
	}

	// Center horizontally
	x := (m.Width - ow + 1) / 2
	// Assume faces are higher up vertically
	y := (m.Height - oh + 1) / 4

	if x < 0 || y < 0 {
		panic("Bad crop offsets!")
	}

	return image.ExtractArea(m.Orientation.Crop(ow, oh, x, y, m.Width, m.Height))
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:19,代码来源:thumbnail.go

示例4: Apply

// Apply executes a set of operations to change the pixel ordering from
// orientation to TopLeft.
func (orientation Orientation) Apply(image *vips.Image) error {
	oi := &orientationInfo[orientation]

	if oi.apply == nil {
		return nil
	}

	// We want to stay sequential, so we copy memory here and execute
	// all work in the pipeline so far.
	if err := image.Write(); err != nil {
		return err
	}

	if err := oi.apply(image); err != nil {
		return err
	}

	_ = image.ImageRemove(vips.ExifOrientation)

	return nil
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:23,代码来源:orientation.go

示例5: MetadataImage

// MetadataImage returns Metadata from an Image. Format is always unset.
func MetadataImage(image *vips.Image) Metadata {
	o := DetectOrientation(image)
	w, h := o.Dimensions(image.Xsize(), image.Ysize())
	if w <= 0 || h <= 0 {
		panic("Invalid image dimensions.")
	}
	return Metadata{Width: w, Height: h, Orientation: o, HasAlpha: image.HasAlpha()}
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:9,代码来源:metadata.go

示例6: minTransparency

func minTransparency(image *vips.Image) (float64, error) {
	if !image.HasAlpha() {
		return 1.0, nil
	}

	band, err := image.Copy()
	if err != nil {
		return 0, err
	}
	defer band.Close()

	if err := band.ExtractBand(band.ImageGetBands()-1, 1); err != nil {
		return 0, err
	}

	// If all pixels are at least 90% opaque, we can flatten.
	min, err := band.Min()
	if err != nil {
		return 0, err
	}

	return min / band.MaxAlpha(), nil
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:23,代码来源:utils.go

示例7: jpegSave

func jpegSave(image *vips.Image, options SaveOptions) ([]byte, error) {
	// JPEG interlace saves 2-3%, but incurs a few hundred bytes of
	// overhead, requires buffering the image completely in RAM for
	// encoding and decoding, and takes over 3x the CPU.  This isn't
	// usually beneficial on small images and is too expensive for large
	// images.
	pixels := image.Xsize() * image.Ysize()
	interlace := pixels >= 200*200 && pixels <= 1024*1024

	// Strip and optimize both save space, enable them.
	return image.JpegsaveBuffer(true, options.Quality, true, interlace)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:12,代码来源:save.go

示例8: useLossless

func useLossless(image *vips.Image, options SaveOptions) bool {
	if !options.Lossless {
		return false
	}

	if !options.LossyIfPhoto {
		return true
	}

	// Mobile devices start being unwilling to load >= 3 megapixel PNGs.
	// Also we don't want to bother to edge detect on large images.
	if image.Xsize()*image.Ysize() >= 3*1024*1024 {
		return false
	}

	// Take a histogram of a Sobel edge detect of our image.  What's the
	// highest number of histogram values in a row that are more than 1%
	// of the maximum value? Above 16 indicates a photo.
	metric, err := image.PhotoMetric(0.01)
	return err != nil || metric < 16
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:21,代码来源:save.go

示例9: pngSave

func pngSave(image *vips.Image, options SaveOptions) ([]byte, error) {
	// PNG interlace is larger; don't use it.
	return image.PngsaveBuffer(true, options.Compression, false)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:4,代码来源:save.go

示例10: transverse

func transverse(image *vips.Image) error {
	if err := image.Flip(vips.DirectionVertical); err != nil {
		return err
	}
	return image.Rot(vips.Angle270)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:6,代码来源:orientation.go

示例11: rot270

func rot270(image *vips.Image) error {
	return image.Rot(vips.Angle270)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:3,代码来源:orientation.go

示例12: rot180

func rot180(image *vips.Image) error {
	return image.Rot(vips.Angle180)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:3,代码来源:orientation.go

示例13: rot90

func rot90(image *vips.Image) error {
	return image.Rot(vips.Angle90)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:3,代码来源:orientation.go

示例14: flop

func flop(image *vips.Image) error {
	return image.Flip(vips.DirectionHorizontal)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:3,代码来源:orientation.go

示例15: flip

func flip(image *vips.Image) error {
	return image.Flip(vips.DirectionVertical)
}
开发者ID:kitwalker12,项目名称:fotomat,代码行数:3,代码来源:orientation.go


注:本文中的github.com/kitwalker12/fotomat/vips.Image类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。