base64转换为图片
package main import ( "encoding/base64" "io/ioutil" "os" "strings" ) func main() { cc, _ := ioutil.ReadFile("a.png.txt") //解压 i := strings.Index(string(cc), ",") cc = cc[i+1:] dist, _ := base64.StdEncoding.DecodeString(string(cc)) //写入新文件 f, _ := os.OpenFile("b.png", os.O_RDWR|os.O_CREATE, os.ModePerm) defer f.Close() f.Write(dist) }
a.png.txt
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIQAAACEAQMAAABrihHkAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABjklEQVRIie3UMYorMQwG4B9c+AouDLqGO1/lwVwgBwhkINcI7FXczTUELtxO6cKgp8km7LLvTaLp1+VXjDTybwG/580RKdx41MoXWXekYGnkI4j/4GSWpS8gkjHiNA6J9yFG5ldS0ANHHJKC0jhU4fjV83sRWUILNdb4NZ+fAnhpAdV9m+t70YkFQGsJX2azeEEXuAGqH3bJWViLE4+zW3eklNTRtUPHBySVzuSFSeTDLotk6d5BSObTjvSyaDQik7vW2SxJEJgG9AojzJJ9odYjOzc/5vyvlOT1L2oc8fJMlEHy0gnsBDFOs1mKXiJ7iWNom2ZJ2/SYuNL8+M7/JJGgsotTXc3ikzTc0/J8FxbpKQt9poXWHckivdFgqVUOiJYLQWfm+FHLIskX4c/MA3uSMtp2F1RvJ7Nk3ZkSWHQ5XFezaIMNW+aje2TeIrqffdiqj+mGHdn2mL9nQ3/eLLozG2+ZJ7nOR0R3OEMw8emFYHunNM520Q7p3qGbzzCL7ueupWW422U1y+95cf4CpjqI2bSOQ48AAAAASUVORK5CYII=