mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-16 10:55:54 -07:00
feat(version): v1 release. see history for details
This commit is contained in:
parent
a0fc602e69
commit
c57a8c1320
14 changed files with 181 additions and 108 deletions
18
type.go
18
type.go
|
|
@ -1,17 +1,24 @@
|
|||
package bimg
|
||||
|
||||
// ImageType represents an image type value.
|
||||
type ImageType int
|
||||
|
||||
const (
|
||||
// UNKNOWN represents an unknow image type value.
|
||||
UNKNOWN ImageType = iota
|
||||
// JPEG represents the JPEG image type.
|
||||
JPEG
|
||||
// WEBP represents the WEBP image type.
|
||||
WEBP
|
||||
// PNG represents the PNG image type.
|
||||
PNG
|
||||
// TIFF represents the TIFF image type.
|
||||
TIFF
|
||||
// MAGICK represents the libmagick compatible genetic image type.
|
||||
MAGICK
|
||||
)
|
||||
|
||||
// Pairs of image type and its name
|
||||
// ImageTypes stores as pairs of image types supported and its alias names.
|
||||
var ImageTypes = map[ImageType]string{
|
||||
JPEG: "jpeg",
|
||||
PNG: "png",
|
||||
|
|
@ -20,22 +27,22 @@ var ImageTypes = map[ImageType]string{
|
|||
MAGICK: "magick",
|
||||
}
|
||||
|
||||
// Determines the image type format (jpeg, png, webp or tiff)
|
||||
// DetermineImageType determines the image type format (jpeg, png, webp or tiff)
|
||||
func DetermineImageType(buf []byte) ImageType {
|
||||
return vipsImageType(buf)
|
||||
}
|
||||
|
||||
// Determines the image type format by name (jpeg, png, webp or tiff)
|
||||
// DetermineImageTypeName determines the image type format by name (jpeg, png, webp or tiff)
|
||||
func DetermineImageTypeName(buf []byte) string {
|
||||
return ImageTypeName(vipsImageType(buf))
|
||||
}
|
||||
|
||||
// Check if a given image type is supported
|
||||
// IsTypeSupported checks if a given image type is supported
|
||||
func IsTypeSupported(t ImageType) bool {
|
||||
return ImageTypes[t] != ""
|
||||
}
|
||||
|
||||
// Check if a given image type name is supported
|
||||
// IsTypeNameSupported checks if a given image type name is supported
|
||||
func IsTypeNameSupported(t string) bool {
|
||||
for _, name := range ImageTypes {
|
||||
if name == t {
|
||||
|
|
@ -45,6 +52,7 @@ func IsTypeNameSupported(t string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// ImageTypeName is used to get the human friendly name of an image format.
|
||||
func ImageTypeName(t ImageType) string {
|
||||
imageType := ImageTypes[t]
|
||||
if imageType == "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue