First commit
This commit is contained in:
commit
0efcaebc39
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal 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
8
.idea/.gitignore
vendored
Normal 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
7
.idea/discord.xml
Normal 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
8
.idea/modules.xml
Normal 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
9
.idea/png2ico.iml
Normal 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
6
.idea/vcs.xml
Normal 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>
|
53
png2ico.go
Normal file
53
png2ico.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user