First commit

This commit is contained in:
Melon 2022-03-07 16:32:51 +00:00
commit bee8e49eba
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6
10 changed files with 103 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# Environment variables file
.env
# Distributable directory
dist/
# Test data and logs folders
.data/
.idea/dataSources.xml

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/discord.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/svg2png.iml" filepath="$PROJECT_DIR$/.idea/svg2png.iml" />
</modules>
</component>
</project>

9
.idea/svg2png.iml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

4
README.md Normal file
View File

@ -0,0 +1,4 @@
svg2png
===========
Convert SVG image to PNG image

14
go.mod Normal file
View File

@ -0,0 +1,14 @@
module tea.melonie54.xyz/sean/svg2png
go 1.17
require (
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780
)
require (
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect
golang.org/x/text v0.3.6 // indirect
)

14
go.sum Normal file
View File

@ -0,0 +1,14 @@
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI=
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 h1:oDMiXaTMyBEuZMU53atpxqYsSB3U1CHkeAu2zr6wTeY=
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 h1:DZshvxDdVoeKIbudAdFEKi+f70l51luSy/7b76ibTY0=
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

29
svg2png.go Normal file
View File

@ -0,0 +1,29 @@
package svg2png
import (
"bytes"
"github.com/srwiley/oksvg"
"github.com/srwiley/rasterx"
"image"
"image/png"
"io"
)
func RasterSvgToPng(r io.Reader) ([]byte, error) {
svg, err := oksvg.ReadIconStream(r, oksvg.StrictErrorMode)
if err != nil {
return nil, err
}
w, h := int(svg.ViewBox.W), int(svg.ViewBox.H)
img := image.NewRGBA(image.Rect(0, 0, w, h))
scannerGV := rasterx.NewScannerGV(0, 0, img, img.Bounds())
raster := rasterx.NewDasher(w, h, scannerGV)
svg.Draw(raster, 1)
b := new(bytes.Buffer)
err = png.Encode(b, img)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}