mirror of
https://github.com/gen2brain/cam2ip.git
synced 2025-12-16 04:18:39 +00:00
Add timestamp option
This commit is contained in:
@@ -7,9 +7,14 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pbnjay/pixfont"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
)
|
||||
|
||||
@@ -129,9 +134,6 @@ func (c *Camera) Read() (img image.Image, err error) {
|
||||
}
|
||||
|
||||
img = c.frame
|
||||
if c.opts.Rotate == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
switch c.opts.Rotate {
|
||||
case 90:
|
||||
@@ -142,6 +144,17 @@ func (c *Camera) Read() (img image.Image, err error) {
|
||||
img = imaging.Rotate270(img)
|
||||
}
|
||||
|
||||
if c.opts.Timestamp {
|
||||
dimg, ok := img.(draw.Image)
|
||||
if !ok {
|
||||
err = fmt.Errorf("camera: %T is not a drawable image type", img)
|
||||
return
|
||||
}
|
||||
|
||||
pixfont.DrawString(dimg, 10, 10, time.Now().Format("2006-01-02 15:04:05"), color.White)
|
||||
img = dimg
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user