-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIconTool.ps1
979 lines (967 loc) · 50.3 KB
/
IconTool.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
################################################################################
# #
# Icon Tool GUI #
# #
################################################################################
# #
# Extracts and exports icons/images to various formats #
# #
################################################################################
#
# Based on PS scripts, modules and associated work by:
# Boe Prox https://learn-powershell.net/about/
# Chrissy LeMaire
# Thomas Levesque http://bit.ly/1KmLgyN
# Darkfall http://git.io/vZxRK
#
# Forms implementation and additional work by:
# Sceptico http://sceptico.wordpress.com
#
################################################################################
#
# 08/01/20 v0.40 Work on export logic for image files
# v0.50 Test release version
# v0.60 Added ability to import images
# v0.70 Can export both icon and image types to Base64
# Optional formatting
# v0.72 Image save working, need to rectify bitmaps for non-square images
# 11/01/20 v0.76 Non-square exports working for bitmaps
# v0.80 Image resizing
# v0.81 Tidy code
# Fix small bug in B64 export
# 14/01/20 v0.85 Fix bug in resetting app for new images
# Set up tab order
# Fix bug in tall image icon export
# 16/01/20 v0.87 Fix bug in adding code example
# 20/01/20 v0.90 Fix bug in file type splitting
# v0.91 Move icon extractor class setup to after form shown
# 23/01/20 v0.92 Changed tempfile deletion to use Remove-Item
#
################################################################################
#
#
$Version = 'v0.92'
#
Try {
Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
Add-Type -AssemblyName System.Drawing -ErrorAction Stop
[Windows.Forms.Application]::EnableVisualStyles()
}
Catch {
$_.Exception.Message
Pause
Break
}
#
#Region B64Images
$DasImage = 'iVBORw0KGgoAAAANSUhEUgAAAPEAAABOCAIAAAB+NWf+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACo2SURBVHhe7Z15IJXL+8BfayhbaCUVspSkECqRFmv2nSwlhEqLtHfbVyV1pbqlUkpa
7LSglDWEyJ59PdbjHMfZ3t/MeU9u9/7upi63r87njznPzDsz7ztznnebeed52FAURViwGEOwM39ZsBgrjLhOv02KcrCz2XMsmBn/R3TKKOkxxb+Bsmm927p1TqVNBBApz35maWlX0oTDtv01y1YZMaXPVFdVMaWv5w+OfMb06Uzpq5CZNYMp
fRX4siyHfWeZEQa4pk80pvh7NunNy+9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ywuJYHItjcViMJUv+D9wko9Uw
QbjKAAAAAElFTkSuQmCC'
#EndRegion B64Images
#
#Region CodeExample
$CodeText = @'
#
#
# Paste Base64 data string into these variables as required
#
# Embedded image
$EmbedImage = ''
#
# Form Icon
$AppIcon = ''
#
# Now we convert Base64 data back to objects
#
Function Get-ImgStreamFromB64 ($B64Img) {
$Bytes = [Convert]::FromBase64String($B64Img)
$stream = New-Object IO.MemoryStream($Bytes, 0, $Bytes.Length)
$stream.Write($Bytes, 0, $Bytes.Length);
Return $stream
}
#
$MyImg = New-Object System.Drawing.Bitmap -Argument (Get-ImgStreamFromB64 $EmbedImage)
$MyIcon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument (Get-ImgStreamFromB64 $AppIcon)).GetHIcon())
#
#
# Now use Image/Icon in form e.g.
$form = New-Object System.Windows.Forms.Form
$form.size = '500,500'
$form.Icon = $MyIcon
$EmbedImage = New-Object System.Windows.Forms.PictureBox
$EmbedImage.Width = $MyImg.Width
$EmbedImage.Height = $MyImg.Height
$EmbedImage.Location = New-Object System.Drawing.Point(($form.Width - $MyImg.Width - 30), (10))
$EmbedImage.Image = $MyImg
$EmbedImage.Anchor = 'Top,Right'
$form.Controls.Add($EmbedImage)
#
# Show form
$form.ShowDialog() | Out-Null
$form.Dispose()
#
'@ -replace "`n", ""
#EndRegion CodeExample
#
# Convert Base64 data back to object
Function Get-ImgStreamFromB64 ($B64Img) {
$Bytes = [Convert]::FromBase64String($B64Img)
$stream = New-Object IO.MemoryStream($Bytes, 0, $Bytes.Length)
$stream.Write($Bytes, 0, $Bytes.Length);
Return $stream
}
#
$MyImg = New-Object System.Drawing.Bitmap -Argument (Get-ImgStreamFromB64 $DASImage)
$MyIcon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument (Get-ImgStreamFromB64 $AppIcon)).GetHIcon())
#
$DefaultFont = New-Object System.Drawing.Font("Segoe", 8)
#
$ValidFileTypes = 'ico','bmp','png','jpg','jpeg','gif','emf','exif','tiff','wmf'
$ValidIcoSizes = '8','16','24','32','48','64','96','128'
#
Function Select-Folder ($RootFolder) {
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.Description = 'Select a folder'
$FolderBrowser.ShowNewFolderButton = $false
$FolderBrowser.SelectedPath = $RootFolder
$result = $FolderBrowser.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }))
If ($result -eq [Windows.Forms.DialogResult]::OK){
$FolderBrowser.SelectedPath
}
Else {
Return 'Invalid Path'
exit
}
}
#
#Region FormElements
$form = New-Object System.Windows.Forms.Form
$form.Font = $DefaultFont
$form.Text = "IconTool - $Version"
$form.MinimumSize = '525,675'
$form.MaximumSize = '525,1400'
$form.StartPosition = 'CenterScreen'
$form.MaximizeBox = $false
$form.Icon = $MyIcon
#Autoscaling settings
$form.AutoScale = $true
$form.AutoScaleMode = "Font"
#
# File selection #
$InputGrpBox = New-Object System.Windows.Forms.GroupBox
$InputGrpBox.Location = '15,20'
$InputGrpBox.Size = '230,95'
$InputGrpBox.Text = 'Browse to file/image for icon(s)'
$InputGrpBox.TabIndex = 1
# Zone Dropdown
$InputFile = New-Object System.Windows.Forms.TextBox
$InputFile.Location = '10,25'
$InputFile.Size = '210,19'
$InputFile.ReadOnly = $true
$InputFile.Enabled = $false
$InputFile.TabStop = $false
#
$BrowseBtn = New-Object System.Windows.Forms.Button
$BrowseBtn.Location = '135,55'
$BrowseBtn.Size = '80,27'
$BrowseBtn.Text = 'Browse'
$BrowseBtn.TabStop = $true
$BrowseBtn.TabIndex = 1
#
#
# Branding image for form
$DASImage = New-Object System.Windows.Forms.PictureBox
$DASImage.Width = $MyImg.Width
$DASImage.Height = $MyImg.Height
$DASImage.Location = New-Object System.Drawing.Point(($form.Width - $MyImg.Width - 30), (10))
$DASImage.Image = $MyImg
$DASImage.Anchor = 'Top,Right'
#
#
# List of icons in source file
$IconList = New-Object System.Windows.Forms.DataGridView
$IconList.RowHeadersVisible = $false
$IconList.ColumnHeadersVisible = $true
$IconList.AllowUserToAddRows = $false
$IconList.ReadOnly = $true
$IconList.SelectionMode = 'FullRowSelect'
$IconList.RowTemplate.Height = 64
$IconList.MultiSelect = $false
$IcListImage = New-Object System.Windows.Forms.DataGridViewImageColumn
$IcListImage.Name = 'IconImage'
$IconList.ColumnCount = 1
$IconList.Columns[0].Name = 'Index'
$IconList.Columns[0].DefaultCellStyle.Alignment = 'MiddleCenter'
$IconList.Columns[0].AutoSizeMode = 'ColumnHeader'
$IconList.Columns.Add($IcListImage) | Out-Null
$IconList.Columns[1].AutoSizeMode = 'Fill'
$IconList.Location = '15,125'
$IconList.Size = '203,369'
$IconList.Anchor = 'Top,Left,Bottom'
$IconList.TabIndex = 2
$IconList.TabStop = $true
#
#
# Groupbox for export path
$ExpPathGrp = New-Object System.Windows.Forms.GroupBox
$ExpPathGrp.Location = '225,125'
$ExpPathGrp.Size = '270,54'
$ExpPathGrp.Text = 'Select path for exported data/file'
$ExpPathGrp.Enabled = $false
$ExpPathGrp.TabIndex = 3
#
$ExportText = New-Object System.Windows.Forms.Label
$ExportText.Location = '10,23'
$ExportText.Size = '155,19'
$ExportText.AutoEllipsis = $true
$ExportText.Text = "$env:USERPROFILE\Downloads"
#
$ExportPathBtn = New-Object System.Windows.Forms.Button
$ExportPathBtn.Location = '175,16'
$ExportPathBtn.Size = '80,27'
$ExportPathBtn.Text = 'Browse'
$ExportPathBtn.Enabled = $true
$ExportPathBtn.TabStop = $true
$ExportPathBtn.TabIndex = 1
#
#
# Groupbox for icon sources
$ExportGrpBox = New-Object System.Windows.Forms.GroupBox
$ExportGrpBox.Location = '225,185'
$ExportGrpBox.Size = '270,310'
$ExportGrpBox.Text = 'Export selected item to required format'
$ExportGrpBox.Enabled = $false
$ExportGrpBox.TabIndex = 4
$ExportGrpBox.Anchor = 'Top,Right'
#
$B64RadioBtn = New-Object System.Windows.Forms.RadioButton
$B64RadioBtn.Location = '10,25'
$B64RadioBtn.Size = '160,17'
$B64RadioBtn.Text = "Convert to Base64 string"
$B64RadioBtn.Checked = $true
$B64RadioBtn.TabStop = $true
$B64RadioBtn.TabIndex = 1
#
$B64ExportType = New-Object System.Windows.Forms.CheckBox
$B64ExportType.Location = '30,45'
$B64ExportType.Size = '200,19'
$B64ExportType.Text = 'Include code examples for PS Forms'
$B64ExportType.TextAlign = 'BottomLeft'
$B64ExportType.TabIndex = 2
#
$B64Format = New-Object System.Windows.Forms.CheckBox
$B64Format.Location = '30,65'
$B64Format.Size = '200,19'
$B64Format.Text = 'Format Base64 for legibility:'
$B64Format.TextAlign = 'BottomLeft'
$B64Format.Checked = $true
$B64Format.TabIndex = 3
#
$FormatLines = New-Object System.Windows.Forms.ComboBox
$FormatLines.Location = '53,88'
$FormatLines.Size = '60,30'
$FormatLines.Enabled = $true
$FormatLines.Items.AddRange(@('100','120','140','160','180','200'))
$FormatLines.SelectedIndex = 3
$FormatLines.TabIndex = 4
#
$FormatLabel = New-Object System.Windows.Forms.Label
$FormatLabel.Location = '120,91'
$FormatLabel.Size = '160,17'
$FormatLabel.Text = 'characters per line'
#
$ExportRadioBtn = New-Object System.Windows.Forms.RadioButton
$ExportRadioBtn.Location = '10,122'
$ExportRadioBtn.Size = '140,17'
$ExportRadioBtn.Text = "Save to image file"
$ExportRadioBtn.TabStop = $true
$ExportRadioBtn.TabIndex = 5
#
$ExpText = New-Object System.Windows.Forms.Label
$ExpText.Location = '30,148'
$ExpText.Size = '140,17'
$ExpText.Text = 'Filetype:'
#
$ExportFormat = New-Object System.Windows.Forms.ComboBox
$ExportFormat.Location = '100,145'
$ExportFormat.Size = '60,30'
$ExportFormat.Items.AddRange($ValidFileTypes)
$ExportFormat.SelectedIndex = 0
$ExportFormat.Enabled = $false
$ExportFormat.TabIndex = 6
$ExportFormat.TabStop = $true
#
$ExpText = New-Object System.Windows.Forms.Label
$ExpText.Location = '30,148'
$ExpText.Size = '70,17'
$ExpText.Text = 'File Type:'
#
$ImgSize = New-Object System.Windows.Forms.ComboBox
$ImgSize.Location = '100,175'
$ImgSize.Size = '60,25'
$ImgSize.Items.AddRange($ValidIcoSizes)
$ImgSize.SelectedIndex = 3
$ImgSize.Enabled = $false
$ImgSize.TabIndex = 7
$ImgSize.TabStop = $true
#
$IcnText = New-Object System.Windows.Forms.Label
$IcnText.Location = '30,178'
$IcnText.Size = '70,17'
$IcnText.Text = 'Icon Size:'
#
$ImgText = New-Object System.Windows.Forms.Label
$ImgText.Location = '30,208'
$ImgText.Size = '70,17'
$ImgText.Text = 'Image Size:'
#
$ImgX = New-Object System.Windows.Forms.TextBox
$ImgX.Location = '100,205'
$ImgX.Size = '50,19'
$imgX.TextAlign = 'Center'
$ImgX.Enabled = $false
$ImgX.TabIndex = 8
#
$ImgSep = New-Object System.Windows.Forms.Label
$ImgSep.Location = '155,208'
$ImgSep.Size = '15,17'
$ImgSep.Text = 'x'
#
$ImgY = New-Object System.Windows.Forms.TextBox
$ImgY.Location = '170,205'
$ImgY.Size = '50,19'
$ImgY.TextAlign = 'Center'
$ImgY.Enabled = $false
$ImgY.TabIndex = 9
#
$ExportBtn = New-Object System.Windows.Forms.Button
$ExportBtn.Location = '155,265'
$ExportBtn.Size = '100,32'
$ExportBtn.Text = 'Export Data/File'
$ExportBtn.Enabled = $true
$ExportBtn.TabStop = $true
$ExportBtn.TabIndex = 10
#
#
# Info/Log window
$LoggingText = New-Object System.Windows.Forms.TextBox
$LoggingText.Location = '15,505'
$LoggingText.Size = '480,120'
$LoggingText.Enabled = $true
$LoggingText.Multiline = $true
$LoggingText.ScrollBars = "Vertical"
$LoggingText.ReadOnly = $true
$LoggingText.Anchor = 'Bottom,Left'
$LoggingText.TabStop = $false
#
#
# Add objects to form
$InputGrpBox.Controls.AddRange(@($InputFile,$BrowseBtn))
$ExpPathGrp.Controls.AddRange(@($ExportText,$ExportPathBtn))
$ExportGrpBox.Controls.AddRange(@($ExportFormat,$B64RadioBtn,$ExpText,$B64ExportType,$B64Format,$FormatLines,$FormatLabel,$ExportRadioBtn,$ImgSize,$IcnText,$ImgText,$ImgX,$ImgSep,$ImgY,$ExportBtn))
$form.Controls.AddRange(@($InputGrpBox,$DASImage,$IconList,$ExpPathGrp,$ExportGrpBox,$LoggingText))
#
#EndRegion FormElements
#
# File browser dialog
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$FileBrowser.title = "Pick image or icon source file"
$FileBrowser.filter = "Image File | *.ico;*.bmp;*.png;*.jpg;*.jpeg;*.gif;*.emf;*.exif;*.tiff;*.wmf | Icon Source | *.exe;*.dll;*.icl"
#
Function ResetUI {
$IconList.Rows.Clear()
$ExportFormat.SelectedIndex = 0
$ImgX.Enabled = $false
$ImgY.Enabled = $false
$Script:ImgRatio = $null
$Script:Source = $null
$ImgX.Text = $null
$ImgY.Text = $null
$ExpPathGrp.Enabled = $false
$B64RadioBtn.Checked = $true
$InputFile.Text = $null
}
#
#
# Form events
$BrowseBtn.Add_Click({
ResetUI
$null = $FileBrowser.ShowDialog()
If ($FileBrowser.FileName) {
Try {
[string]$InputFileType = ([IO.Path]::GetExtension($FileBrowser.FileName)).Split(".")[1]
$LoggingText.AppendText("`r`nFile type: $InputFileType")
}
Catch {
$LoggingText.AppendText("`r`nError determining file type`r`n" + "$_")
}
If ($InputFileType -in ('exe','dll','icl')) {
# Icon source, extract icons to list
$LoggingText.AppendText("`r`nIcon source")
$Script:Source = 'Icon'
$SelectedFile = $InputFile.Text = $FileBrowser.FileName
$index = 0
$LoggingText.AppendText("`r`nExtracting icons from $SelectedFile")
Do {
Try {
$icon = [System.IconExtractor]::Extract($SelectedFile, $index, $true)
}
Catch {
$LoggingText.AppendText("`r`nCould not extract icon.`r`n" + "$_")
}
Try {
If ($icon) {
$IcoImage = $icon.ToBitmap()
$IconList.Rows.Add($index,$IcoImage)
$icon.Dispose()
}
}
Catch {
$LoggingText.AppendText("`r`nError`r`n" + "$_")
}
$index++
} While ($icon -ne $null)
If ($index = 0) {
$LoggingText.AppendText("`r`nNo icons to extract")
}
Else {
$ExpPathGrp.Enabled = $true
}
}
ElseIf ($InputFileType -in $ValidFileTypes) {
# Image Source
$ImageObj = $Canvas = $Graphic = $null
$PreviewSize = 64
$LoggingText.AppendText("`r`nImage source")
$Script:Source = 'Image'
$SelectedFile = $InputFile.Text = $FileBrowser.FileName
Try {
$ImageObj = [System.Drawing.Image]::FromFile((Get-Item $SelectedFile -ErrorAction Stop))
[int]$DefImgX = $ImgX.Text = $ImageObj.Width
[int]$DefImgY = $ImgY.Text = $ImageObj.Height
$Script:ImgRatio = $DefImgX / $DefImgY
# $LoggingText.AppendText("`r`nPreviewSize = $PreviewSize`r`nRatio = $ImgRatio")
# Create preview image
If ($ImgRatio -eq 1) {
[int]$NewHeight = [int]$NewWidth = $PreviewSize
}
ElseIf ($ImgRatio -gt 1) {
[int]$NewHeight = $PreviewSize / $ImgRatio
[int]$NewWidth = $PreviewSize
}
Else {
[int]$NewHeight = $PreviewSize
[int]$NewWidth = $PreviewSize * $ImgRatio
}
# $LoggingText.AppendText("`r`nNewHeight = $NewHeight`r`nNewWidth = $NewWidth")
$Canvas = New-Object System.Drawing.Bitmap($NewWidth,$NewHeight) -ErrorAction Stop
$Graphic = [System.Drawing.Graphics]::FromImage($Canvas)
$Graphic.DrawImage($ImageObj, 0, 0,$NewWidth,$NewHeight)
$IconList.Rows.Add('-',$Canvas)
$ExpPathGrp.Enabled = $true
}
Catch {
$LoggingText.AppendText("`r`nError: " + "$_")
}
}
Else {
$LoggingText.AppendText("`r`nInvalid file type")
Return
}
}
Else {
$LoggingText.AppendText("`r`nNo file selected")
}
$LoggingText.AppendText("`r`nDone")
If (Test-Path -Path $ExportText.Text) {
$ExportGrpBox.Enabled = $true
}
Else {
$LoggingText.AppendText("`r`nPlease choose valid output path for exported data/file")
}
})
#
$ExportPathBtn.Add_Click({
$ExportGrpBox.Enabled = $false
$ExportPath = Select-Folder "$env:USERPROFILE\Downloads"
If ($ExportPath -ne 'Invalid Path') {
$ExportText.Text = $ExportPath
$ExportGrpBox.Enabled = $true
$LoggingText.AppendText("`r`nExport path will be $ExportPath")
}
Else {
$LoggingText.AppendText("`r`nNo valid folder path selected")
}
})
#
#
$B64RadioBtn.Add_CheckedChanged({
If ($B64RadioBtn.Checked) {
$B64ExportType.Enabled = $B64Format.Enabled = $ExportBtn.Enabled = $FormatLines.Enabled = $true
$ExportFormat.Enabled = $ImgSize.Enabled = $ImgX.Enabled = $false
}
Else {
$B64ExportType.Enabled = $B64Format.Enabled = $FormatLines.Enabled = $false
$ExportBtn.Enabled = $ExportFormat.Enabled = $true
If ($Script:Source -eq 'Icon') {
$ImgX.Enabled = $ImgY.Enabled = $false
$ImgSize.Enabled = $true
}
Else {
$ImgX.Enabled = $ImgY.Enabled = $ImgSize.Enabled = $true
}
If ($ExportFormat.Text -eq 'ico') {
$ImgX.Enabled = $ImgY.Enabled = $false
}
Else {
$ImgX.Enabled = $ImgY.Enabled = $true
}
}
})
#
#
$B64Format.Add_CheckedChanged({
If($B64Format.Checked) {
$FormatLines.Enabled = $true
}
Else {
$FormatLines.Enabled = $false
}
})
#
#
$ExportFormat.Add_SelectedIndexChanged({
If ($Script:Source -ne 'Icon') {
If ($ExportFormat.Text -eq 'ico') {
$ImgX.Enabled = $ImgY.Enabled = $false
$ImgSize.Enabled = $true
}
Else {
$ImgX.Enabled = $ImgY.Enabled = $true
$ImgSize.Enabled = $false
}
}
})
#
#
$ImgX.Add_TextChanged({
If ($ImgX.Enabled) {
$ImgY.Enabled = $false
$ImgY.Text = [int]($ImgX.Text / $Script:ImgRatio)
$ImgY.Enabled = $true
$ImgX.Focus()
$ImgX.Select($ImgX.Text.Length, 0)
}
})
#
#
$ImgY.Add_TextChanged({
If ($ImgY.Enabled) {
$ImgX.Enabled = $false
$ImgX.Text = [int]($ImgY.Text * $Script:ImgRatio)
$ImgX.Enabled = $true
$ImgY.Focus()
$ImgY.Select($ImgY.Text.Length, 0)
}
})
#
#
$ExportBtn.Add_Click({
If ($IconList.SelectedRows) {
$CurIndex = $Iconlist.SelectedRows[0].Index
# Construct output filename
$OutfileName = Join-Path -Path $ExportText.Text -ChildPath ((Split-Path -Path $InputFile.Text -Leaf) + "_" + $CurIndex)
$LoggingText.AppendText("`r`nItem index $CurIndex is selected for processing")
###
# Export to Base64
###
If ($B64RadioBtn.Checked) {
Try {
$LoggingText.AppendText("`r`nConverting to Base64")
Switch ($Script:Source) {
'Icon' {
$LoggingText.AppendText("`r`nIcon source detected")
$LoggingText.AppendText("`r`nProcessing data...")
$icon = [System.IconExtractor]::Extract($InputFile.Text, $CurIndex, $true)
$MemoryStream = New-Object System.IO.MemoryStream -ErrorAction Stop
$Icon.save($MemoryStream)
$Bytes = $MemoryStream.ToArray()
$MemoryStream.Flush()
$MemoryStream.Dispose()
$Base64Out = [convert]::ToBase64String($Bytes)
}
'Image' {
$LoggingText.AppendText("`r`nImage source detected")
$LoggingText.AppendText("`r`nProcessing data...")
$Base64Out = [convert]::ToBase64String((Get-Content -Path $InputFile.Text -Encoding Byte))
}
}
If ($B64Format.Checked) {
# Split B64 data into lines for readability
$LoggingText.AppendText("`r`nFormatting data - this can take a while...")
$Split = While ($Base64Out) {
$x,$Base64Out = ([char[]]$Base64Out).where({$_},'Split',[int]$FormatLines.Text)
$x -join ''
}
}
Else {
$Split = $Base64Out
}
If ($B64ExportType.Checked) {
$LoggingText.AppendText("`r`nAdding code example")
$Split = ($Split + "`r`n" + $CodeText)
}
$SavePath = "$OutfileName-Base64.txt"
$LoggingText.AppendText("`r`n`r`nWriting data to $SavePath")
$Split | Out-File -FilePath $SavePath
$LoggingText.AppendText("`r`nDone`r`n")
}
Catch {
$LoggingText.AppendText("`r`nError`r`n" + "$_")
}
}
###
# Export to file
###
If ($ExportRadioBtn.Checked) {
$bmp = $null
$LoggingText.AppendText("`r`nExporting $Source to file...")
Switch ($Script:Source) {
'Icon' {
$LoggingText.AppendText("as " + $ExportFormat.Text + "`r`n")
Try {
$icon = [System.IconExtractor]::Extract($InputFile.Text, $CurIndex, $true)
$bmp = $icon.ToBitmap()
# Export icon to icon
If ($ExportFormat.Text -eq 'ico') {
$tempfile = "$OutfileName.tmp"
$bmp.Save($tempfile,"png")
$SavePath = "$OutfileName.ico"
$LoggingText.AppendText("`r`nWriting icon to $SavePath")
[PngIconConverter]::Convert($tempfile,$SavePath,$ImgSize.Text,$true) | Out-Null
# Keep remove-item from complaining about weird directories
Remove-Item -Path $tempfile -Force -Confirm:$false -ErrorAction Stop
$LoggingText.AppendText("`r`nDone`r`n")
}
# Export icon to image
Else {
If ($ExportFormat.Text -ne 'jpg') {
$type = $ExportFormat.Text
}
Else {
$type = 'jpeg'
}
$SavePath = "$OutfileName." + $ExportFormat.Text
If ($bmp.Width -ne $ImgSize.Text) {
$LoggingText.AppendText("`r`nBitmap size is " + $bmp.Width + " - resizing image")
# Needs to be resized
[int]$NewWidth = [int]$NewHeight = $ImgSize.Text
$NewBitmap = New-Object System.Drawing.Bitmap($NewWidth,$NewHeight) -ErrorAction Stop
$Graphic = [System.Drawing.Graphics]::FromImage($NewBitmap)
# Make it transparent - need if its not icon?
$LoggingText.AppendText("`r`nAdding transparency")
$Graphic.Clear([System.Drawing.Color]::Transparent)
$Graphic.DrawImage($bmp,0,0,$NewWidth,$NewHeight)
# Save to file
$LoggingText.AppendText("`r`nWriting icon data to $SavePath")
$NewBitmap.Save($SavePath,$type)
$NewBitmap.Dispose()
$LoggingText.AppendText("`r`nDone`r`n")
}
Else {
$LoggingText.AppendText("`r`nWriting data to $SavePath")
$bmp.Save($SavePath,$type)
$LoggingText.AppendText("`r`nDone`r`n")
}
$bmp.Dispose()
}
$icon.Dispose()
}
Catch {
$LoggingText.AppendText("`r`nError resizing/saving as icon" + "$_")
}
}
'Image' {
$LoggingText.AppendText("as " + $ExportFormat.Text + "`r`n")
Try {
$SavePath = "$OutfileName." + $ExportFormat.Text
$ImageObj = $NewBitmap = $Graphic = $null
$SelectedFile = $InputFile.Text
If ($ExportFormat.Text -ne 'jpg') {
$type = $ExportFormat.Text
}
Else {
$type = 'jpeg'
}
#
## Get image
$ImageObj = [System.Drawing.Image]::FromFile((Get-Item $SelectedFile -ErrorAction Stop))
## Save as icon
If ($type -eq 'ico') {
# Resize image
$LoggingText.AppendText("`r`nResizing for icon image...")
[int]$NewHeight = [int]$NewWidth = $ImgSize.Text
$NewBitmap = New-Object System.Drawing.Bitmap($NewWidth,$NewHeight)
$Graphic = [System.Drawing.Graphics]::FromImage($NewBitmap)
# Is image square?
If ($Script:ImgRatio -eq 1) {
$LocationX = 0
$LocationY = 0
}
# Image not square - place into square canvas so that image isn't "squashed"
ElseIf ($Script:ImgRatio -gt 1) {
$LoggingText.AppendText("`r`nWide image, centering on square canvas")
$LoggingText.AppendText("`r`nImage ratio: $ImgRatio")
[int]$NewWidth = $ImgSize.Text
[int]$NewHeight = [int]$ImgSize.Text / $ImgRatio
$LoggingText.AppendText("`r`nSize (x,y): $NewWidth,$NewHeight")
[int]$LocationX = 0
[int]$LocationY = ([int]$NewBitmap.Height - [int]$NewHeight)/2
$LoggingText.AppendText("`r`nLocation (x,y): $LocationX,$LocationY")
}
Else {
$LoggingText.AppendText("`r`nTall image, centering on square canvas")
$LoggingText.AppendText("`r`nImage ratio: $ImgRatio")
[int]$NewWidth = [int]$ImgSize.Text * $ImgRatio
[int]$NewHeight = $ImgSize.Text
$LoggingText.AppendText("`r`nSize (x,y): $NewWidth,$NewHeight")
[int]$LocationX = ([int]$NewBitmap.Width - [int]$NewWidth)/2
[int]$LocationY = 0
$LoggingText.AppendText("`r`nLocation (x,y): $LocationX,$LocationY")
}
# Add transparency
$Graphic.Clear([System.Drawing.Color]::Transparent)
# Write image into location on square bitmap
$Graphic.DrawImage($ImageObj,$LocationX,$LocationY,$NewWidth,$NewHeight)
# Save to PNG temp file
$tempfile = "$OutfileName.tmp"
$NewBitmap.Save($tempfile,"png")
$SavePath = "$OutfileName.ico"
$LoggingText.AppendText("`r`nWriting icon data to $SavePath")
[PngIconConverter]::Convert($tempfile,$SavePath,$ImgSize.Text,$true) | Out-Null
# Keep remove-item from complaining about weird directories
Remove-Item -Path $tempfile -Force -Confirm:$false -ErrorAction Stop
$NewBitmap.Dispose()
#
}
Else {
# Not saving to icon, save to image file
# Create canvas with correct size
$LoggingText.AppendText("`r`nConverting image to $type")
[int]$NewHeight = $ImgY.Text
[int]$NewWidth = $ImgX.Text
$NewBitmap = New-Object System.Drawing.Bitmap($NewWidth,$NewHeight)
$Graphic = [System.Drawing.Graphics]::FromImage($NewBitmap)
$Graphic.DrawImage($ImageObj,0,0,$NewWidth,$NewHeight)
$LoggingText.AppendText("`r`nSaving image as $type")
$SavePath = "$OutfileName." + $type
$NewBitmap.Save($SavePath,$type)
}
}
Catch {
$LoggingText.AppendText("`r`nError resizing/saving as image" + "$_")
}
}
}
$LoggingText.AppendText("`r`nDone`r`n")
}
ResetUI
}
Else {
$LoggingText.AppendText("`r`nNo item selected for processing")
}
})
#
$form.Add_Shown({
#Region IconExtrator
$LoggingText.AppendText("`r`nLoading icon extractor")
$code = '
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.IO;
namespace System {
public class IconExtractor {
public static Icon Extract(string file, int number, bool largeIcon) {
IntPtr large;
IntPtr small;
ExtractIconEx(file, number, out large, out small, 1);
try { return Icon.FromHandle(largeIcon ? large : small); }
catch { return null; }
}
[DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
}
}
public class PngIconConverter
{
public static bool Convert(System.IO.Stream input_stream, System.IO.Stream output_stream, int size, bool keep_aspect_ratio = false)
{
System.Drawing.Bitmap input_bit = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(input_stream);
if (input_bit != null)
{
int width, height;
if (keep_aspect_ratio)
{
width = size;
height = input_bit.Height / input_bit.Width * size;
}
else
{
width = height = size;
}
System.Drawing.Bitmap new_bit = new System.Drawing.Bitmap(input_bit, new System.Drawing.Size(width, height));
if (new_bit != null)
{
System.IO.MemoryStream mem_data = new System.IO.MemoryStream();
new_bit.Save(mem_data, System.Drawing.Imaging.ImageFormat.Png);
System.IO.BinaryWriter icon_writer = new System.IO.BinaryWriter(output_stream);
if (output_stream != null && icon_writer != null)
{
icon_writer.Write((byte)0);
icon_writer.Write((byte)0);
icon_writer.Write((short)1);
icon_writer.Write((short)1);
icon_writer.Write((byte)width);
icon_writer.Write((byte)height);
icon_writer.Write((byte)0);
icon_writer.Write((byte)0);
icon_writer.Write((short)0);
icon_writer.Write((short)32);
icon_writer.Write((int)mem_data.Length);
icon_writer.Write((int)(6 + 16));
icon_writer.Write(mem_data.ToArray());
icon_writer.Flush();
return true;
}
}
return false;
}
return false;
}
public static bool Convert(string input_image, string output_icon, int size, bool keep_aspect_ratio = false)
{
System.IO.FileStream input_stream = new System.IO.FileStream(input_image, System.IO.FileMode.Open);
System.IO.FileStream output_stream = new System.IO.FileStream(output_icon, System.IO.FileMode.OpenOrCreate);
bool result = Convert(input_stream, output_stream, size, keep_aspect_ratio);
input_stream.Close();
output_stream.Close();
return result;
}
}
'
#EndRegion IconExtractor
# Add IconExtrator class
Try {
Add-Type -TypeDefinition $code -ReferencedAssemblies System.Drawing, System.IO -ErrorAction Stop
$LoggingText.AppendText("`r`nDone")
}
Catch {
$LoggingText.AppendText("`r`nError" + "$_")
}
})
#
# Show form
$form.ShowDialog() | Out-Null
$form.Dispose()
# End