當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。