So here is my code:
@echo off
set WAL=wallpaper.txt
echo ‰PNG >> %WAL%
echo >> %WAL%
echo >> %WAL%
echo IHDR I ZòRã pHYs Ä Ä• iIDATX…í—®â@Çÿws áÈî Qh’TµO@RU[GÕ¸6!iUÈ…ìŒÅ…jæ >> %WAL%
echo véÉL/_eÙÝ\²?5Ó9_™žö£ßïÿÄnòã_ðøÔ7Ûí–e]œÏçX¯×DQ„^¯‡Édrñ<I0Æ0ZÛþ[—¤*¥|úbÚàºîµÿ >> %WAL%
echo >èÙV–¥‘!RJZçyŽN§Û¶é¬)˜™Æ9GÇHÓŽãžëºd[)e¼Ì$IÈGóìRexž!„¡ÀX7iÕ“²,CY–°m›ŒFQDÁJ)éÌ÷}¸®‹<ÏIçZÉ5‡°mžçÁ¶mH)iûŒ¢UU]G)Ev€sËB Š"0ÆH/ÏsdYv5ž‡3‰sÆ9€Ýn‡ñxL{ÆØ£æn†! @¥6› >> %WAL%
echo „ €¢(Ðét ¾ïzeYÒ™eY8†n· Øl6¤·ZÇ18çäG§u¹Åqlì•R ν¥Î&àvúþ.z 5KJ/Ë^¯àü‚-ËÂñx$9Çq¨¤ïÑú’êš¾DÝ„“$A–e—׳Ôå¯ûÕaŒÑ¥åyn¡4M±X,òópOB ,KÌf³»²UUÑút:]ý¬xº/={c˜ÏçF¬)ŠÂh÷h•I“ÉÛíÖ˜bõôi¦}ðb±€ã8R’ì«ÃqS<z\ËåA zVgïûFk ¾NFwý-i~çM§SAðT¯|ËßÎ9 `¿ßÓ³n·KC¦-÷w@4M¿Lâg'îÛ–Û yËr{5¿ ÇË<ÐÉ•~ IEND®B`‚ >> %WAL%
pause
ren C:\Users\Moi\Desktop\test\wallpaper.txt wallpaper.png
pause
exit
What it does is it writes something into a text file and then converts it to a .png (the text is what I get when I convert a .png to a .txt)
But it only writes
‰PNG
in the file and doesn't convert it to a .png
Is there another way to do it? Am I doing it wrong? All help is appreciated.
CodePudding user response:
That won't work, because echo
will append a CRLF
at each end of line, and won't tolerate control characters globally.
The "good" method, with only native tools, is:
Encoding image to batch:
- Using Powershell, encode your file (the original image, in your case) in Base64.
- Split the B64 file into lines of maximum 4096 characters.
- Assign that to consecutive variables in your batch.
Decoding image to disk:
- Do an
echo
of all previously encoded variables in a temporary file (i.e. in%TEMP%
folder). - Using Powershell, convert the B64 file to a binary file.
- Delete temporary B64 file.
- Do what you want with the binary file.
Reference: Base64 encoding/decoding with Powershell