Favicon

Emile_esp
Posts: 5
Joined: Wed Jan 04, 2023 10:02 am

Re: Favicon

Postby Emile_esp » Wed Jan 04, 2023 10:20 am

I have used a powershell script to convert the Favicon.ico ( but also HTML files )
So that i do not need to escape all type of // \\ '' and so on.

Code: Select all

#include "IR.htm.h" // This is the file IR.htm converted in Array IR_htm  
void handleRoot() {
  server.send_P(200, "text/html", IR_htm, sizeof(IR_htm) );
}

#include "favicon.ico.h" // This is the file favicon.ico converted in Array favicon_ico 
void faviconico()
{ 
  server.send_P(200, "image/x-icon", favicon_ico , sizeof(favicon_ico));
}


And the Powershell

Code: Select all

function ConvertToBin($path)
{
	Write-Output "const char $((Split-Path $path -leaf).Replace('.','_'))[] PROGMEM = {"
	$arrayFromFile = Get-Content -Encoding byte -Path ".\$path"
	$i=0;
	$line="";
	$linetxt="";
	foreach($item in $arrayFromFile)
	{
	  if($i) { $line+= ","} else { $line+= " "} 	
	  $line+= "0x$(([int]$item).ToString('X2'))" 
	  if (($item -ge 32) -and ($item -le 126) -and !($item -eq [int]([char]'\'))) { $linetxt+=[char]$item;} else {$linetxt+='.';}
	  $i+=1
	  if(!($i % 31))  { 
	  #Write-Output "$line"; 
	  Write-Output "$line // $linetxt"; 
	  $line="" ; $linetxt="" }
	}
	if($i % 31)  {  
	  Write-Output "$line // $linetxt";
	  } 
	Write-Output "};"
	#Write-Output "$(Split-Path $path -Parent)\$(Split-Path $path -leaf).h"
}  

function ConvertFileToBin ($file)
{
	
ConvertToBin($file) | Out-File -FilePath "$file.h" -Encoding ASCII
	
}
ConvertFileToBin('IR.htm')
ConvertFileToBin('favicon.ico')

Who is online

Users browsing this forum: No registered users and 83 guests