imageKit

package
v2.2.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decode func(r io.Reader) (image.Image, string, error) = image.Decode

Decode 解码图片

@param r 类型可以是: *os.File(用完记得调用Close())

Functions

func Convert

func Convert(src, dest string) error

Convert 转换图片的格式.

!!!: (1) 因为 h2non/bimg 基于C语言的libvip库,因此使用要满足"一些条件",详见: https://mp.weixin.qq.com/s/kAFZohzJo2DiKkxjnVti6A (2) bug: 转换后,透明背景色 可能=> 黑色背景色(即使目标格式支持透明背景色); (3) bug: 图片转pdf.

@param dest 如果已经存在且是个文件,会覆盖

支持的格式:

"jpg"
"jpeg"
"png"
"webp"
"tiff"
"gif"
"pdf"
"svg"
"magick"
"heif"
"avif"

func DecodeFromBase64

func DecodeFromBase64(base64 []byte) ([]byte, error)

DecodeFromBase64 图片的base64数据 => 图片的数据(可以直接存储到硬盘上)

@param base64 带不带前缀都无所谓(e.g. "data:image/png;base64,"、"data:image/jpeg;base64,"、"data:image/gif;base64,")

func DecodeToImageFile

func DecodeToImageFile(base64 []byte, dest string, perm os.FileMode) error

DecodeToImageFile

@param target 要生成的图片的路径

func DecodeWithPath

func DecodeWithPath(src string) (image.Image, string, error)

DecodeWithPath 解码图片

func EncodeToBase64String

func EncodeToBase64String(data []byte) (string, error)

func GetImageBase64

func GetImageBase64(imagePath string) (string, error)

GetImageBase64 (硬盘上的)图片 => base64字符串

参考: golang 将图片生成Base64 https://blog.csdn.net/weixin_40292098/article/details/126029489

func GetImageType

func GetImageType(path string) (bimg.ImageType, error)

GetImageType 根据 文件名 判断图片类型.

func GetWebImageBase64

func GetWebImageBase64(url string) (string, error)

GetWebImageBase64 网络图片 => base64字符串

参考: golang 将图片生成Base64 https://blog.csdn.net/weixin_40292098/article/details/126029489

@param url e.g."https://img.redocn.com/sheying/20150507/pugongying_4267498.jpg"

func ToJpeg

func ToJpeg(src, dest string, qualityArgs ...int8) error

ToJpeg 将图片格式转换为".jpg"(||".jpeg")

@param qualityArgs (默认: 100; 取值范围: [1, 100])生成jpeg图片的质量

func ToPng

func ToPng(src, dest string) error

ToPng 将图片格式转换为".png"

Types

type Info

type Info struct {
	ExtName    string      `json:"extName"`
	ColorModel color.Model `json:"colorModel"`

	Width  int `json:"width"`
	Height int `json:"height"`
}

func GetInfo

func GetInfo(path string) (*Info, error)

GetInfo 获取图片的信息(宽、高、后缀名).

【图像处理】Golang 获取常用图像的宽高总结

https://www.cnblogs.com/voipman/p/16108320.html

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL