mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
Refactoring IsTypeSupport to deal with save.
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
parent
dcd91c85e0
commit
a2ba03da29
4 changed files with 86 additions and 24 deletions
14
vips.go
14
vips.go
|
|
@ -386,7 +386,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
|||
interlace := C.int(boolToInt(o.Interlace))
|
||||
quality := C.int(o.Quality)
|
||||
|
||||
if o.Type != 0 && !VipsIsTypeSupportedSave(o.Type) {
|
||||
if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
|
||||
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
|
||||
}
|
||||
var ptr unsafe.Pointer
|
||||
|
|
@ -520,24 +520,24 @@ func vipsImageType(buf []byte) ImageType {
|
|||
if buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF {
|
||||
return JPEG
|
||||
}
|
||||
if IsImageTypeSupportedByVips(WEBP) && buf[8] == 0x57 && buf[9] == 0x45 && buf[10] == 0x42 && buf[11] == 0x50 {
|
||||
if IsTypeSupported(WEBP) && buf[8] == 0x57 && buf[9] == 0x45 && buf[10] == 0x42 && buf[11] == 0x50 {
|
||||
return WEBP
|
||||
}
|
||||
if IsImageTypeSupportedByVips(TIFF) &&
|
||||
if IsTypeSupported(TIFF) &&
|
||||
((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) ||
|
||||
(buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) {
|
||||
return TIFF
|
||||
}
|
||||
if IsImageTypeSupportedByVips(GIF) && buf[0] == 0x47 && buf[1] == 0x49 && buf[2] == 0x46 {
|
||||
if IsTypeSupported(GIF) && buf[0] == 0x47 && buf[1] == 0x49 && buf[2] == 0x46 {
|
||||
return GIF
|
||||
}
|
||||
if IsImageTypeSupportedByVips(PDF) && buf[0] == 0x25 && buf[1] == 0x50 && buf[2] == 0x44 && buf[3] == 0x46 {
|
||||
if IsTypeSupported(PDF) && buf[0] == 0x25 && buf[1] == 0x50 && buf[2] == 0x44 && buf[3] == 0x46 {
|
||||
return PDF
|
||||
}
|
||||
if IsImageTypeSupportedByVips(SVG) && IsSVGImage(buf) {
|
||||
if IsTypeSupported(SVG) && IsSVGImage(buf) {
|
||||
return SVG
|
||||
}
|
||||
if IsImageTypeSupportedByVips(MAGICK) && strings.HasSuffix(readImageType(buf), "MagickBuffer") {
|
||||
if IsTypeSupported(MAGICK) && strings.HasSuffix(readImageType(buf), "MagickBuffer") {
|
||||
return MAGICK
|
||||
}
|
||||
return UNKNOWN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue