Jump to content

image to binary


iamtheky
 Share

Recommended Posts

takes an image and turns it into an autoit usable binary representation, and shellexecutes the au3 (because im set to bring it up in Scite, suppose it will not play nicely if you are set to execute au3s)

As always please turn this into something shiny and even more useful, so i can use that. Sorry if there already scripts in abundance that do this.

#include <array.au3>
#include <file.au3>

Global $fixarray

$pic = fileopen ("C:\Program Files\AutoIt3\Examples\GUI\merlin.gif" , 16)

$read = fileread($pic)

fileclose ($pic)

$write = fileopen (@ScriptDir & "\binaryPic.txt" , 2)

filewrite ($write , string($read))

fileclose ($write)

$readfile = fileread (@ScriptDir & "\binaryPic.txt")

$readarray = StringSplit ($readfile, "" , 2)


$testwrite = fileopen (@ScriptDir &  "\BinaryPic.au3" , 2)

Filewrite ($testwrite , "Global $Pic_2_Binary = ")


for $L = 0 to ubound ($readarray) - 1 step 121


    If $L + 120 > ubound ($readarray) - 1 Then
        Filewrite ($testwrite , '"')
    for $i = $L to ubound ($readarray) - 1
    Filewrite ($testwrite , $readarray[$i])
  Next
Filewrite ($testwrite , '"')

  Else
      Filewrite ($testwrite , '"')
    for $i = $L to $L + 120
        Filewrite ($testwrite , $readarray[$i])
    next
    Filewrite ($testwrite , '"')
  Endif


 FileWrite ($testwrite , @CRLF & "$Pic_2_Binary &= ")

  Next

fileclose ($testwrite)

_FileReadToArray (@ScriptDir & "\BinaryPic.au3" , $fixarray)

_ArrayDelete ($fixarray, $fixarray[0])
_ArrayDelete ($fixarray, 0)

_FileWriteFromArray (@ScriptDir & "\BinaryPic.au3" , $fixarray)

filedelete (@ScriptDir &  "\BinaryPic.txt")

ShellExecute (@ScriptDir & "\BinaryPic.au3")
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

There are Examples floating around e..g

This Example was found on the Forum (initially I saw by UEZ) and then modified it myself.

Functions:

Func _FileToAU3Binary($sFile, $sVariable, $sFunction)
    Local $iLength = 160, $sData, $sFileRead, $sFunctionData

    $sData = __GetFile($sFile, 16)

    $sFunctionData = 'Func ' & $sFunction & '()' & @CRLF & @TAB & 'Local $' & $sVariable & ' = "' & StringLeft($sData, $iLength) & '"' & @CRLF
    $sData = StringTrimLeft($sData, $iLength)

    While StringLen($sData) > $iLength
        $sFunctionData &= @TAB & '$' & $sVariable & ' &= "' & StringLeft($sData, $iLength) & '" ' & @CRLF
        $sData = StringTrimLeft($sData, $iLength)
    WEnd

    If StringLen($sData) <> 0 Then
        $sFunctionData &= @TAB & '$' & $sVariable & ' &= "' & $sData & '"'
    EndIf
    $sFunctionData &= @CRLF & @TAB & 'Return $' & $sVariable & @CRLF & 'EndFunc   ;==>' & $sFunction
    ClipPut(__SetFile($sFunctionData, @ScriptDir & "\Function.au3"))
    Return $sFunctionData
EndFunc   ;==>_FileToAU3Binary

Func __GetFile($sFile, $sFormat = 0)
    Local $hFileOpen = FileOpen($sFile, $sFormat), $sData
    If $hFileOpen = -1 Then
        Return SetError(1, 0, "")
    EndIf
    $sData = FileRead($hFileOpen)
    FileClose($hFileOpen)
    Return $sData
EndFunc   ;==>_GetFile

Func __SetFile($sString, $sFile)
    Local $hFileOpen = FileOpen($sFile, 2)
    FileWrite($hFileOpen, $sString)
    FileClose($hFileOpen)
    If @error Then
        Return SetError(1, 0, $sString)
    EndIf
    Return $sString
EndFunc   ;==>__SetFile

Example use of Function:

_FileToAU3Binary("Merlin.gif", "bBinaryPic", "_ImageFile")
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...