mirror of
https://github.com/gen2brain/cam2ip.git
synced 2025-12-16 04:18:39 +00:00
Add functions for rotate and timestamp
This commit is contained in:
40
image/image.go
Normal file
40
image/image.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"time"
|
||||
|
||||
"github.com/anthonynsimon/bild/transform"
|
||||
"github.com/pbnjay/pixfont"
|
||||
)
|
||||
|
||||
func Rotate(img image.Image, angle int) image.Image {
|
||||
switch angle {
|
||||
case 90:
|
||||
img = transform.Rotate(img, 90, &transform.RotationOptions{ResizeBounds: true})
|
||||
case 180:
|
||||
img = transform.Rotate(img, 180, &transform.RotationOptions{ResizeBounds: true})
|
||||
case 270:
|
||||
img = transform.Rotate(img, 270, &transform.RotationOptions{ResizeBounds: true})
|
||||
}
|
||||
|
||||
return img
|
||||
}
|
||||
|
||||
func Timestamp(img image.Image, format string) (image.Image, error) {
|
||||
if format == "" {
|
||||
format = "2006-01-02 15:04:05"
|
||||
}
|
||||
|
||||
dimg, ok := img.(draw.Image)
|
||||
if !ok {
|
||||
return img, fmt.Errorf("camera: %T is not a drawable image type", img)
|
||||
}
|
||||
|
||||
pixfont.DrawString(dimg, 10, 10, time.Now().Format(format), color.White)
|
||||
|
||||
return dimg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user