I have developed a few internal Chocolatey
Packages and the internal repository has no access to Internet. I'd like to have the icon of the packages I have developed to be included in the package itself. Is this possible in Chocolatey
?
Asked
Active
Viewed 276 times
0

Dilshad Abduwali
- 1,388
- 7
- 26
- 47
-
You can embed icons in PS scripts by converting them to Base64 – Scepticalist Dec 20 '19 at 08:07
-
Any example in PS to do that? Thanks – Dilshad Abduwali Dec 21 '19 at 01:39
2 Answers
1
There is nothing currently in Chocolatey that would allow for the embedding on icons into the package. This would also require that the repository that you are using supported extracting the icon from within the package for display. In the interim, my suggestion would be to host the icons internally on your own website, and update the nupsec files with the internal location for the icons.

Gary Ewan Park
- 17,610
- 5
- 42
- 60
0
No idea if this is the sort of thing you need as I don't use Chocolatey but here's how to use Base64 so that you can embed images in your scripts...
Get the image data:
# Path to image file
$PathToSourceImage = 'c:\temp\image.jpg'
$PathToExe = 'c:\temp\example.exe'
# Convert image to Base64 and copy to clipboard - or there's several websites where you can do this.
[convert]::ToBase64String((get-content $PathToSourceImage -encoding byte)) | Clip
You can also extract from icon or executable:
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($PathtoExe)
$MemoryStream = New-Object System.IO.MemoryStream
$Icon.save($MemoryStream)
$Bytes = $MemoryStream.ToArray()
$MemoryStream.Flush()
$MemoryStream.Dispose()
[convert]::ToBase64String($Bytes) | Clip
Now use the image data in your script
# Paste the Base64 data here and assign to a variable.....
$IconBase64 = 'AAABAAEAICAQKAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAA
AP8AAP8AAAD//wD/AAAA/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADMzMzMAAAAAAAAAAAAAczMzM3MzMAAAAAAAAAAAd3M3iIu3dzAAAAAAAAA
Ad3eIi7u7szNwAAAAAAAAAHeIiLu7u7MzMAAAAAAAAACIiIi7u7uzMzAAAAAAAAAAiIiIu7u7szMwAAAAAAAAAIiIiIi7u7uzMAAAAAAAAACIiIiIi7u7u7AAAAAAAAAAiIiIiIi7u7uwAAAAAA
AAAIiIiIiIiLu7sAAAAAAAAACIiIiIiIiHu7AAAAAAAAAAiIiIiId3czdwAAAAAAAAAIiIh3iIiLiHMAAAAAAAAACIh4iLu3iDu4AAAAAAAAAAh4i7u7u4i7sAAAAAAAAAAIi3iLu7uIsAAAAAA
AAAAAC7uIi7u4iLAAAAAAAAAAAAAAuIsACIuwAAAAAAAAAAAAALiAAAiLsAAAAAAAAAAAAAC4sAAIi7AAAAAAAAAAAAAAuLAACIuwAAAAAAAAAAAAALiwAAiLsAAAAAAAAAAAAAC4uACIi7AAAA
AAAAAAAAAAiLsIiIsAAAAAAAAAAAAAAIiIuIi7AAAAAAAAAAAAAAAIiI+LsAAAAAAAAAAAAAAAAIiIuwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////AP/
/8AAf/8AAD/8AAD//AAB//wAAf/8AAH//AAB//wAAf/8AAH//AAB//wAAf/8AAH//AAB//wAAf/8AAP//AAP//wAD///hw///48P//+PD///jw///48P//+GD///hB///4Af///AP///4H////////////w=='
# Convert back to PS icon object
$iconBytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length);
$MyIcon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
# You can also convert to bitmap etc for images
$Bytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($Bytes, 0, $Bytes.Length)
$stream.Write($Bytes, 0, $Bytes.Length);
$MyImg = New-Object System.Drawing.Bitmap -Argument $stream
# Example using Forms
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Font = $DefaultFont
$form.Text = "Test"
$form.Size = '400,400'
$form.StartPosition = 'CenterScreen'
$form.FormBorderStyle = 'FixedSingle'
#
# Using the icon
$form.Icon = $MyIcon
$DASImage = New-Object System.Windows.Forms.PictureBox
$DASImage.Width = $MyImg.Width
$DASImage.Height = $MyImg.Height
$DASImage.Location = '10,10'
$DASImage.Image = $MyImg
$form.Controls.Add($DASImage)
# Show form
$form.ShowDialog() | Out-Null
$form.Dispose()
Ensure your icon images are a suitable size etc

Scepticalist
- 3,737
- 1
- 13
- 30