Giter Club home page Giter Club logo

go-remote2base64's Introduction

go-remote2Base64

go读取远程(公有读)权限图片(腾讯云cos|阿里云oss|aws s3|等)生成base64字符串
前端可以通过 img 标签直接渲染

Installation

go get -u github.com/ctra-wang/go-remote2Base64

Mehtods

GetRemoteConvertBase64()
Base64StrHandler2Base64()

Documentation

used the two libs:

  • github.com/fogleman/gg
  • github.com/polds/imgbase64

1、GetRemoteConvertBase64()

this func accpet the remote imgUrl,and used the lib "github.com/polds/imgbase64" handle the image

params:

1、imgUrl:public imgUrl  (on the web wo can open it) without credentials.
2、tff:if you handle the img,you can upload yourself tff.
3、imgName:the local img,if you get the remote and create the local img file.
4、isDelImg:if isDelImg is true,del the create image,else don`t del.
5、PointInfo:support to drawing the charaters on the image

return :
a base64 image string and error

2、Base64StrHandler2Base64()

you can cache the same base64 url to redis,and other function equals the GetRemoteConvertBase64()

Quick start!

func TestGetRemoteConvertBase64(t *testing.T) {
	imgUrl := "https://img-blog.csdnimg.cn/350174dad84e4ecaa0f7995207791df9.jpeg"
	tff := "longshuhongheicuti.ttf"
	imgName := "test.jpg"
	isDelImg := true
	str, err := GetRemoteConvertBase64(imgUrl, tff, imgName, isDelImg, nil)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(str)
}

Test

base642Image web:https://www.toolnb.com/tools/base64ToImages.html

before convert image url: https://img-blog.csdnimg.cn/350174dad84e4ecaa0f7995207791df9.jpeg

img_1.png

input the return base64Img string,we can get the image

img.png

go-remote2base64's People

Contributors

ctra-wang avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.