mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
1
This commit is contained in:
7
go.mod
7
go.mod
@@ -13,12 +13,15 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||
github.com/gomodule/redigo v2.0.0+incompatible
|
||||
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9
|
||||
github.com/gookit/color v1.2.5
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/jander/golog v0.0.0-20150917071935-954a5be801fc
|
||||
github.com/jinzhu/gorm v1.9.12
|
||||
github.com/jroimartin/gocui v0.4.0
|
||||
github.com/kardianos/service v1.2.1
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/nicksnyder/go-i18n/v2 v2.0.3
|
||||
github.com/nsqio/go-nsq v1.0.8
|
||||
github.com/olivere/elastic v6.2.31+incompatible
|
||||
@@ -54,6 +57,10 @@ require (
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac // indirect
|
||||
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 // indirect
|
||||
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 // indirect
|
||||
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/hashicorp/go-version v1.6.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
|
14
go.sum
14
go.sum
@@ -502,6 +502,16 @@ github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac h1:Q0Jsdxl5jbxouNs1TQYt0gxesYMU4VXRbsTlgDloZ50=
|
||||
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc=
|
||||
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 h1:EvokxLQsaaQjcWVWSV38221VAK7qc2zhaO17bKys/18=
|
||||
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg=
|
||||
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 h1:8jtTdc+Nfj9AR+0soOeia9UZSvYBvETVHZrugUowJ7M=
|
||||
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks=
|
||||
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 h1:7qnwS9+oeSiOIsiUMajT+0R7HR6hw5NegnKPmn/94oI=
|
||||
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A=
|
||||
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9 h1:V2IgdyerlBa/MxaEFRbV5juy/C3MGdj4ePi+g6ePIp4=
|
||||
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||
@@ -677,6 +687,8 @@ github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ=
|
||||
github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
@@ -752,6 +764,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
|
||||
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
|
||||
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
|
||||
github.com/networkplumbing/go-nft v0.2.0/go.mod h1:HnnM+tYvlGAsMU7yoYwXEVLLiDW9gdMmb5HoGcwpuQs=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.0.3 h1:ks/JkQiOEhhuF6jpNvx+Wih1NIiXzUnZeZVnJuI8R8M=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.0.3/go.mod h1:oDab7q8XCYMRlcrBnaY/7B1eOectbvj6B1UPBT+p5jo=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
|
BIN
mydraw/111.jpg
Normal file
BIN
mydraw/111.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 644 KiB |
@@ -2,6 +2,7 @@ package mydraw
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -56,3 +57,13 @@ func TestMytest(t *testing.T) {
|
||||
fmt.Println(b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImg(t *testing.T) {
|
||||
var hdc HDC
|
||||
hdc.SetBg("./src.jpg")
|
||||
img, _ := GetImg("./111.jpg")
|
||||
img = Resize(img, 100, 0)
|
||||
hdc.DrawImg(img, image.Point{100, 200})
|
||||
b := hdc.Save("./out.png")
|
||||
fmt.Println(b)
|
||||
}
|
||||
|
@@ -15,23 +15,11 @@ import (
|
||||
|
||||
"github.com/golang/freetype"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/nfnt/resize"
|
||||
"github.com/xxjwxc/public/mylog"
|
||||
)
|
||||
|
||||
type Pen struct {
|
||||
FontSize float64
|
||||
Dpi float64
|
||||
Font *truetype.Font
|
||||
StartPoint image.Point
|
||||
Color *image.Uniform
|
||||
}
|
||||
|
||||
type HDC struct {
|
||||
//Bg image.Image
|
||||
Rgba *image.RGBA
|
||||
}
|
||||
|
||||
//获取画笔
|
||||
// 获取画笔
|
||||
func OnGetPen(fontPath string, R, G, B, A uint8) (pen Pen, b bool) {
|
||||
b = false
|
||||
pen.Color = image.NewUniform(color.RGBA{R: R, G: G, B: B, A: A})
|
||||
@@ -53,7 +41,40 @@ func OnGetPen(fontPath string, R, G, B, A uint8) (pen Pen, b bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HDC) SetBg(imagePath string) bool {
|
||||
func GetImg(imagePath string) (img image.Image, err error) {
|
||||
file, _ := os.Open(imagePath)
|
||||
defer file.Close()
|
||||
//var err error
|
||||
img, _, err = image.Decode(file)
|
||||
if err != nil {
|
||||
fmt.Println("err = ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return img, nil
|
||||
}
|
||||
|
||||
// Resize 设置图片高宽
|
||||
func Resize(img image.Image, width, height uint) image.Image {
|
||||
// dx := img.Bounds().Dx()
|
||||
// dy := img.Bounds().Dy()
|
||||
return resize.Resize(width, height, img, resize.Lanczos3)
|
||||
}
|
||||
|
||||
type Pen struct {
|
||||
FontSize float64
|
||||
Dpi float64
|
||||
Font *truetype.Font
|
||||
StartPoint image.Point
|
||||
Color *image.Uniform
|
||||
}
|
||||
|
||||
type HDC struct {
|
||||
//Bg image.Image
|
||||
Rgba *image.RGBA
|
||||
}
|
||||
|
||||
func (h *HDC) SetBg(imagePath string) bool {
|
||||
file, _ := os.Open(imagePath)
|
||||
defer file.Close()
|
||||
//var err error
|
||||
@@ -63,21 +84,21 @@ func (this *HDC) SetBg(imagePath string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
this.Rgba = image.NewRGBA(img.Bounds())
|
||||
draw.Draw(this.Rgba, this.Rgba.Bounds(), img, image.ZP, draw.Src)
|
||||
h.Rgba = image.NewRGBA(img.Bounds())
|
||||
draw.Draw(h.Rgba, h.Rgba.Bounds(), img, image.ZP, draw.Src)
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HDC) GetBgSize() (w, h int) {
|
||||
b := this.Rgba.Bounds()
|
||||
func (h *HDC) GetBgSize() (w, _h int) {
|
||||
b := h.Rgba.Bounds()
|
||||
w = b.Max.X
|
||||
h = b.Max.Y
|
||||
_h = b.Max.Y
|
||||
return
|
||||
}
|
||||
|
||||
//图片上画文字
|
||||
func (this *HDC) DrawText(pen Pen, text string) bool {
|
||||
if this.Rgba == nil {
|
||||
// 图片上画文字
|
||||
func (h *HDC) DrawText(pen Pen, text string) bool {
|
||||
if h.Rgba == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -85,8 +106,8 @@ func (this *HDC) DrawText(pen Pen, text string) bool {
|
||||
c.SetDPI(pen.Dpi)
|
||||
c.SetFont(pen.Font)
|
||||
c.SetFontSize(pen.FontSize)
|
||||
c.SetClip(this.Rgba.Bounds())
|
||||
c.SetDst(this.Rgba)
|
||||
c.SetClip(h.Rgba.Bounds())
|
||||
c.SetDst(h.Rgba)
|
||||
//c.SetSrc(image.NewUniform(color.RGBA{255, 255, 255, 255}))
|
||||
c.SetSrc(pen.Color)
|
||||
|
||||
@@ -103,8 +124,16 @@ func (this *HDC) DrawText(pen Pen, text string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
//保存图片
|
||||
func (this *HDC) Save(imagePath string) bool {
|
||||
// 图片上画图片
|
||||
func (h *HDC) DrawImg(img image.Image, point image.Point) {
|
||||
draw.Draw(h.Rgba, h.Rgba.Bounds().Add(point),
|
||||
img,
|
||||
img.Bounds().Min,
|
||||
draw.Over)
|
||||
}
|
||||
|
||||
// 保存图片
|
||||
func (h *HDC) Save(imagePath string) bool {
|
||||
output, err := os.OpenFile(imagePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
mylog.Error(err)
|
||||
@@ -113,9 +142,9 @@ func (this *HDC) Save(imagePath string) bool {
|
||||
defer output.Close()
|
||||
|
||||
if strings.HasSuffix(imagePath, ".png") || strings.HasSuffix(imagePath, ".PNG") {
|
||||
err = png.Encode(output, this.Rgba)
|
||||
err = png.Encode(output, h.Rgba)
|
||||
} else {
|
||||
err = jpeg.Encode(output, this.Rgba, nil)
|
||||
err = jpeg.Encode(output, h.Rgba, nil)
|
||||
}
|
||||
if err != nil {
|
||||
mylog.Infof("image encode error(%v)", err)
|
||||
|
BIN
mydraw/src.jpg
Normal file
BIN
mydraw/src.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
@@ -14,7 +14,7 @@ func TestMain(t *testing.T) {
|
||||
}
|
||||
fmt.Println(triton.ServerLive(context.Background()))
|
||||
out, _ := triton.RequestFromText(context.Background(), "texts", "你好", "sentence_embedding")
|
||||
f32 := triton.BytesToFloat64(out)
|
||||
f32 := triton.BytesToFloat32(out)
|
||||
fmt.Println(f32)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user