First commit

This commit is contained in:
Melon 2022-03-07 16:36:41 +00:00
commit 0efcaebc39
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6
10 changed files with 108 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/png2ico.iml" filepath="$PROJECT_DIR$/.idea/png2ico.iml" />
</modules>
</component>
</project>

9
.idea/png2ico.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>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

4
README.md Normal file
View File

@ -0,0 +1,4 @@
png2ico
===========
Convert PNG image to ICO image

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module tea.melonie54.xyz/sean/png2ico
go 1.17

53
png2ico.go Normal file
View File

@ -0,0 +1,53 @@
package png2ico
import (
"bytes"
"encoding/binary"
)
type iconDir struct {
reserved uint16
imageType uint16
numImages uint16
}
type iconDirEntry struct {
imageWidth uint8
imageHeight uint8
numColors uint8
reserved uint8
colorPlanes uint16
bitsPerPixel uint16
sizeInBytes uint32
offset uint32
}
func newIconDir() iconDir {
return iconDir{imageType: 1, numImages: 1}
}
func newIconDirEntry() iconDirEntry {
return iconDirEntry{colorPlanes: 1, bitsPerPixel: 32, offset: 22}
}
func ConvertPngToIco(im []byte, width, height int) ([]byte, error) {
id := newIconDir()
ide := newIconDirEntry()
ide.sizeInBytes = uint32(len(im))
ide.imageWidth = uint8(width)
ide.imageHeight = uint8(height)
bb := new(bytes.Buffer)
err := binary.Write(bb, binary.LittleEndian, id)
if err != nil {
return nil, err
}
err = binary.Write(bb, binary.LittleEndian, ide)
if err != nil {
return nil, err
}
bb.Write(im)
return bb.Bytes(), nil
}