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


Golang Image.HasAlpha方法代码示例

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


在下文中一共展示了Image.HasAlpha方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: resize

func resize(image *vips.Image, iw, ih int, fastResize bool, blurSigma float64, sharpen bool) error {
	m := format.MetadataImage(image)

	// Interpolation of RGB values with an alpha channel isn't safe
	// unless the values are pre-multiplied. Undo this later.
	// This also flattens fully transparent pixels to black.
	premultiply := image.HasAlpha()
	if premultiply {
		if err := image.Premultiply(); err != nil {
			return err
		}
	}

	// A box filter will quickly get us within 2x of the final size, at some quality cost.
	if fastResize {
		// Shrink factors can be passed independently here, which
		// may not be sane since Resize()'s blur and sharpening
		// steps expect a normal aspect ratio.
		wshrink := math.Floor(float64(m.Width) / float64(iw))
		hshrink := math.Floor(float64(m.Height) / float64(ih))
		if wshrink >= 2 || hshrink >= 2 {
			// Shrink rounds down the number of pixels.
			if err := image.Shrink(wshrink, hshrink); err != nil {
				return err
			}
			m = format.MetadataImage(image)
		}
	}

	// If necessary, do a high-quality resize to scale to final size.
	if iw < m.Width || ih < m.Height {
		// Vips 8.3 sometimes produces 1px smaller images than desired without the rounding help here.
		if err := image.Resize((float64(iw)+vips.ResizeOffset)/float64(m.Width), (float64(ih)+vips.ResizeOffset)/float64(m.Height)); err != nil {
			return err
		}
	}

	if blurSigma > 0.0 {
		if err := image.Gaussblur(blurSigma); err != nil {
			return err
		}
	}

	if sharpen {
		if err := image.MildSharpen(); err != nil {
			return err
		}
	}

	// Unpremultiply after all operations that touch adjacent pixels.
	if premultiply {
		if err := image.Unpremultiply(); err != nil {
			return err
		}
	}

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

示例4: 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


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