github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/renderers/xdg/icon.go (about) 1 package xdg 2 3 import ( 4 "bytes" 5 _ "embed" 6 "os" 7 8 "github.com/pojntfx/hydrapp/hydrapp/pkg/renderers" 9 "github.com/pojntfx/hydrapp/hydrapp/pkg/utils" 10 ) 11 12 type iconRenderer struct { 13 inputFilePath string 14 outputFilePath string 15 16 imageType utils.ImageType 17 18 width int 19 height int 20 } 21 22 func NewIconRenderer( 23 inputFilePath string, 24 outputFilePath string, 25 26 imageType utils.ImageType, 27 28 width int, 29 height int, 30 ) renderers.Renderer { 31 return &iconRenderer{ 32 inputFilePath: inputFilePath, 33 outputFilePath: outputFilePath, 34 35 imageType: imageType, 36 37 width: width, 38 height: height, 39 } 40 } 41 42 func (r *iconRenderer) Render(templateOverride string) (filePath string, fileContent []byte, err error) { 43 inputFile, err := os.Open(r.inputFilePath) 44 if err != nil { 45 return "", []byte{}, err 46 } 47 defer inputFile.Close() 48 49 outputFile := &bytes.Buffer{} 50 if err := utils.ConvertPNG( 51 inputFile, 52 outputFile, 53 54 r.imageType, 55 56 r.width, 57 r.height, 58 ); err != nil { 59 return "", []byte{}, err 60 } 61 62 return r.outputFilePath, outputFile.Bytes(), nil 63 }