mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-11 00:10:27 -07:00
fix(crop): tests
This commit is contained in:
parent
2e90c11e5b
commit
03f08422d8
8 changed files with 86 additions and 17 deletions
55
metadata.go
Normal file
55
metadata.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package bimg
|
||||
|
||||
/*
|
||||
#cgo pkg-config: vips
|
||||
#include "vips/vips.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import ()
|
||||
|
||||
type ImageSize struct {
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
type ImageMetadata struct {
|
||||
Orientation int
|
||||
Alpha bool
|
||||
Profile bool
|
||||
Space int
|
||||
Type string
|
||||
Size ImageSize
|
||||
}
|
||||
|
||||
func Size(buf []byte) (ImageSize, error) {
|
||||
metadata, err := Metadata(buf)
|
||||
if err != nil {
|
||||
return ImageSize{}, err
|
||||
}
|
||||
|
||||
return ImageSize{
|
||||
Width: int(metadata.Size.Width),
|
||||
Height: int(metadata.Size.Height),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Metadata(buf []byte) (ImageMetadata, error) {
|
||||
defer C.vips_thread_shutdown()
|
||||
|
||||
image, imageType, err := vipsRead(buf)
|
||||
if err != nil {
|
||||
return ImageMetadata{}, err
|
||||
}
|
||||
defer C.g_object_unref(C.gpointer(image))
|
||||
|
||||
metadata := ImageMetadata{
|
||||
Type: getImageTypeName(imageType),
|
||||
Size: ImageSize{
|
||||
Width: int(image.Xsize),
|
||||
Height: int(image.Ysize),
|
||||
},
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue