Documentation
¶
Index ¶
- Variables
- func Base64ToFile(base64Str, outputPath string) error
- func Clip(img image.Image, x, y, width, height int) (image.Image, error)
- func ClipWithPath(srcPath, dstPath string, x, y, width, height int) error
- func DecodeFromBase64(base64 []byte) ([]byte, error)
- func DecodeFromPath(path string) (img image.Image, format string, err error)
- func DecodeToImageFile(base64 []byte, dest string, perm os.FileMode) error
- func DecodeWithBytes(imgData []byte) (img image.Image, format string, err error)
- func Encode(file io.Writer, img image.Image, ext string) (err error)
- func EncodeToBase64String(data []byte) (string, error)
- func EncodeToPath(path string, img image.Image) (err error)
- func GetBase64ImageExt(base64Str string) (string, error)
- func GetImageBase64(imagePath string) (string, error)
- func GetSize(path string) (width int, height int, err error)
- func GetWebImageBase64(url string) (string, error)
- func Resize(srcPath, dstPath string, width, height int) (err error)
- func ResizeByHeight(srcPath, dstPath string, height int) (err error)
- func ResizeByWidth(srcPath, dstPath string, width int) (err error)
- func ResizeImage(srcImg image.Image, width, height int) (image.Image, error)
- func ResizeImageByHeight(srcImg image.Image, height int) (image.Image, error)
- func ResizeImageByWidth(srcImg image.Image, width int) (image.Image, error)
- func ResizeImageKeepAspectRatio(srcImg image.Image, maxWidth, maxHeight int) (image.Image, error)
- func ResizeImageWithScale(srcImg image.Image, scale float64) (image.Image, error)
- func ResizeKeepAspectRatio(srcPath, dstPath string, maxWidth, maxHeight int) (err error)
- func ResizeWithScale(srcPath, dstPath string, scale float64) (err error)
- func ToBmp(src, dest string) error
- func ToJpeg(src, dest string, qualityArgs ...int8) error
- func ToPng(src, dest string) error
- func ToTiff(src, dest string, opts *tiff.Options) error
- func TrimTransparentForPng(inputPath, outputPath string) error
- type Info
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Base64ToFile ¶
Base64ToFile 将base64字符串转换为图片文件 参数:
- base64Str: base64编码的图片字符串,可能包含"data:"前缀
- outputPath: 输出文件路径
返回:
- error: 错误信息,成功则返回nil
func Clip ¶
Clip 裁剪图片.
@param img 原始图片实例(不能为nil!) @param x, y 裁剪区域左上角坐标 @param width, height 裁剪区域的宽度和高度
func ClipWithPath ¶ added in v3.26.103
ClipWithPath 裁剪图片.
func DecodeFromBase64 ¶
DecodeFromBase64 图片的base64数据 => 图片的数据(可以直接存储到硬盘上)
@param base64 带不带前缀都无所谓(e.g. "data:image/png;base64,"、"data:image/jpeg;base64,"、"data:image/gif;base64,")
func DecodeWithBytes ¶
DecodeWithBytes []byte => image.Image
func EncodeToBase64String ¶
func EncodeToPath ¶
EncodeToPath image.Image => 文件
func GetBase64ImageExt ¶
GetBase64ImageExt 从 base64 字符串中识别图片格式并返回文件后缀
@return 文件扩展名(小写 && 带"."),e.g. ".jpg" ".png"
func GetImageBase64 ¶
GetImageBase64 (硬盘上的)图片 => base64字符串
参考: golang 将图片生成Base64 https://blog.csdn.net/weixin_40292098/article/details/126029489
func GetWebImageBase64 ¶
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 Resize ¶
Resize 缩放图片到指定尺寸(不保证纵横比).
@param srcPath 源图片文件路径 @param dstPath 目标图片文件路径 @param width 目标宽度(像素) @param height 目标高度(像素) @return 返回错误信息,如果成功则返回 nil
func ResizeByHeight ¶
ResizeByHeight 按高度等比例缩放图片.
func ResizeByWidth ¶
ResizeByWidth 按宽度等比例缩放图片.
func ResizeImage ¶
ResizeImage 缩放图片到指定尺寸(不保证纵横比).
func ResizeImageKeepAspectRatio ¶
ResizeImageKeepAspectRatio 按比例调整图片大小(保证纵横比;适应指定尺寸).
@param src 源图片对象 @param maxWidth 最大宽度 @param maxHeight 最大高度
func ResizeImageWithScale ¶
ResizeImageWithScale 按指定比例缩放图片(保证纵横比).
func ResizeKeepAspectRatio ¶
ResizeKeepAspectRatio 按比例调整图片大小(保证纵横比;适应指定尺寸).
func ResizeWithScale ¶
ResizeWithScale 按指定比例缩放图片(保证纵横比).
func ToJpeg ¶
ToJpeg 将图片格式转换为".jpg"(||".jpeg").
@param qualityArgs (默认: 100; 取值范围: [1, 100])生成jpeg图片的质量
func TrimTransparentForPng ¶
TrimTransparentForPng 裁剪 .png 图片的透明边缘.
@param inputPath 输入图片的路径,要求后缀为.png @param outputPath 输出图片的路径,为空则覆盖原文件