Jump to content

Search the Community

Showing results for tags 'svg'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 5 results

  1. Is it somehow possible to use SVGPathElement DOM interface to convert a SVG file to polygons within AutoIt? load a SVG file with AutoIt convert the SVG vectors to polygons using this interface export the polygons to a file I don't know whether it works also for multi vectorized objects. An example is here: http://phrogz.net/svg/convert_path_to_polygon.xhtml / http://stackoverflow.com/questions/8091983/convert-path-to-polygon / https://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement I've absolutely no experiences with this kind of stuff (you know it is not GDI+ ;-)) THANKS.
  2. I can't show SVG content using _IEWriteDocHTML! If i save the same SVG code into a file and navigate to the file, it works. Global $oIE = _IECreateEmbedded() GUICreate('TEXT?',180,99,5,5, BitOR(0x00C00000, 0x00080000)) GUICtrlCreateObj($oIE,4,4,172,64) _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, '<HTML><BODY><svg xmlns="http://www.w3.org/2000/svg" width="400" height="110"> <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" /> Sorry, your browser does not support inline SVG. </svg></BODY></HTML>') While 1 GUISetState() ; This part will show svg not supported message! Wend _IENavigate($oIE, @ScriptDir&'\1.svg') While 1 GUISetState() ; This part will show svg correctly. Wend If i use _IECreate() it works too. I'm on win 10 x64 with IE 11
  3. wakillon

    Svg2Png

    Version 1.0.0

    364 downloads

    Convert SVG file to PNG using Cairo and rsvg libraries
  4. Convert SVG file to PNG using Cairo and rsvg libraries (and their imports) #Region ;************ Includes ************ #include <File.au3> #EndRegion ;************ Includes ************ ; typedef enum _cairo_status Global Const $CAIRO_STATUS_SUCCESS = 0 Global Const $CAIRO_STATUS_NO_MEMORY = 1 Global Const $CAIRO_STATUS_INVALID_RESTORE = 2 Global Const $CAIRO_STATUS_INVALID_POP_GROUP = 3 Global Const $CAIRO_STATUS_NO_CURRENT_POINT = 4 Global Const $CAIRO_STATUS_INVALID_MATRIX = 5 Global Const $CAIRO_STATUS_INVALID_STATUS = 6 Global Const $CAIRO_STATUS_NULL_POINTER = 7 Global Const $CAIRO_STATUS_INVALID_STRING = 8 Global Const $CAIRO_STATUS_INVALID_PATH_DATA = 9 Global Const $CAIRO_STATUS_READ_ERROR = 10 Global Const $CAIRO_STATUS_WRITE_ERROR = 11 Global Const $CAIRO_STATUS_SURFACE_FINISHED = 12 Global Const $CAIRO_STATUS_SURFACE_TYPE_MISMATCH = 13 Global Const $CAIRO_STATUS_PATTERN_TYPE_MISMATCH = 14 Global Const $CAIRO_STATUS_INVALID_CONTENT = 15 Global Const $CAIRO_STATUS_INVALID_FORMAT = 16 Global Const $CAIRO_STATUS_INVALID_VISUAL = 17 Global Const $CAIRO_STATUS_FILE_NOT_FOUND = 18 Global Const $CAIRO_STATUS_INVALID_DASH = 19 Global Const $CAIRO_STATUS_INVALID_DSC_COMMENT = 20 Global Const $CAIRO_STATUS_INVALID_INDEX = 21 Global Const $CAIRO_STATUS_CLIP_NOT_REPRESENTABLE = 22 Global Const $CAIRO_STATUS_TEMP_FILE_ERROR = 23 Global Const $CAIRO_STATUS_INVALID_STRIDE = 24 Global Const $CAIRO_STATUS_FONT_TYPE_MISMATCH = 25 Global Const $CAIRO_STATUS_USER_FONT_IMMUTABLE = 26 Global Const $CAIRO_STATUS_USER_FONT_ERROR = 27 Global Const $CAIRO_STATUS_NEGATIVE_COUNT = 28 Global Const $CAIRO_STATUS_INVALID_CLUSTERS = 29 Global Const $CAIRO_STATUS_INVALID_SLANT = 30 Global Const $CAIRO_STATUS_INVALID_WEIGHT = 31 Global Const $CAIRO_STATUS_INVALID_SIZE = 32 Global Const $CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED = 33 Global Const $CAIRO_STATUS_DEVICE_TYPE_MISMATCH = 34 Global Const $CAIRO_STATUS_DEVICE_ERROR = 35 Global Const $CAIRO_STATUS_INVALID_MESH_CONSTRUCTION = 36 Global Const $CAIRO_STATUS_DEVICE_FINISHED = 37 Global Const $CAIRO_STATUS_LAST_STATUS = 38 ; typedef enum _cairo_format Global Const $CAIRO_FORMAT_INVALID = -1 Global Const $CAIRO_FORMAT_ARGB32 = 0 Global Const $CAIRO_FORMAT_RGB24 = 1 Global Const $CAIRO_FORMAT_A8 = 2 Global Const $CAIRO_FORMAT_A1 = 3 Global Const $CAIRO_FORMAT_RGB16_565 = 4 Global Const $CAIRO_FORMAT_RGB30 = 5 ; Check libraries. $aList = _FileListToArray ( @ScriptDir, '*.dll', 1, 0 ) For $i = 1 To UBound ( $aList ) -1 If _GetBinaryType ( @ScriptDir & '\' & $aList[$i] ) <> 'i386' Then Exit MsgBox ( 262144+16, 'Error', $aList[$i] & ' is not 32bit !', 5 ) ;~ ConsoleWrite ( $aList[$i] & @TAB & 'Version ' & FileGetVersion ( $aList[$i] ) & @Crlf ) Next #Region ------ Global Variables ------------------------------ FileChangeDir ( @ScriptDir & '\Libraries' ) Global $h_RsvgDll = DllOpen ( @ScriptDir & '\Libraries\librsvg-2-2.dll' ) Global $h_CairoDll = DllOpen ( @ScriptDir & '\Libraries\libcairo-2.dll' ) Global $sPngFilePath = @DesktopDir & '\' & @HOUR & @MIN & @SEC & @MSEC & '.png' Global $sSvgFilePath, $hRsvg, $pCairoSurface, $pCr #EndRegion --- Global Variables ------------------------------ FileChangeDir ( @ScriptDir & '\SVG files' ) $sSvgFilePath = FileOpenDialog ( 'Select a Shape', @WorkingDir, 'Vector Graphic (*.svg)', 1+2, '' ) If @error Then Exit ; Open the SVG image file $hRsvg = _Rsvg_handle_new_from_file ( $sSvgFilePath ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $hRsvg : ' & $hRsvg & @Crlf ) ; Get dimensions $aSize = _Rsvg_handle_get_dimensions ( $hRsvg ) If Not @error Then ConsoleWrite ( '> Width : ' & $aSize[0] & ', Height : ' & $aSize[1] & @Crlf ) ; Create a Surface into which we render the SVG drawing $pCairoSurface = _Cairo_image_surface_create ( $CAIRO_FORMAT_ARGB32, $aSize[0], $aSize[1] ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $pCairoSurface : ' & $pCairoSurface & @Crlf ) ; Create a new Cairo renderer $pCr = _Cairo_create ( $pCairoSurface ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $pCr : ' & $pCr & @Crlf ) ConsoleWrite ( 'Cairo status after _Cairo_create : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Render the SVG into the Cairo buffer _Rsvg_handle_render_cairo ( $hRsvg, $pCr ) ConsoleWrite ( 'Cairo status after _Rsvg_handle_render_cairo : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Save to png _Cairo_surface_write_to_png ( $pCairoSurface, $sPngFilePath ) ConsoleWrite ( 'Cairo status after _Cairo_surface_write_to_png : ' & _Cairo_status ( $pCr ) & @Crlf ) _Cairo_surface_finish ( $pCairoSurface ) ConsoleWrite ( 'Cairo status after _Cairo_surface_finish : ' & _Cairo_status ( $pCr ) & @Crlf ) _Rsvg_handle_close ( $hRsvg ) ConsoleWrite ( 'Cairo status after _Rsvg_handle_close : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Display _BitmapDisplayInWindowsViewer ( $sPngFilePath ) ; Cleanup _Cairo_destroy ( $pCr ) _Cairo_surface_destroy ( $pCairoSurface ) DllClose ( $h_RsvgDll ) DllClose ( $h_CairoDll ) Exit Func _BitmapDisplayInWindowsViewer ( $sFilePath ) If Not FileExists ( $sFilePath ) Then Return SetError ( -1 ) Run ( 'rundll32 shimgvw.dll,ImageView_Fullscreen ' & $sFilePath ) EndFunc ;==> _BitmapDisplayInWindowsViewer() Func _Cairo_create ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_create', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_create() Func _Cairo_destroy ( $pCr ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_destroy', 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_destroy() Func _Cairo_image_surface_create ( $iFormat, $iWidth, $iHeight ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_image_surface_create', 'int', $iFormat, 'int', $iWidth, 'int', $iHeight ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_image_surface_create() Func _Cairo_image_surface_create_for_data ( $iFormat, $iWidth, $iHeight, $iStride ) Local $tStruct = DllStructCreate ( 'byte[' & $iStride*$iHeight & ']' ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_image_surface_create_for_data', 'ptr', DllStructGetPtr ( $tStruct ), 'int', $iFormat, 'int', $iWidth, 'int', $iHeight, 'int', $iStride ) If @error Then Return SetError ( @error, 0, 0 ) $tStruct = 0 Return $aRet[0] EndFunc ;==> _Cairo_image_surface_create_for_data() Func _Cairo_status ( $pCr ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_status', 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Switch $aRet[0] Case $CAIRO_STATUS_SUCCESS Return 'SUCCESS' Case $CAIRO_STATUS_NO_MEMORY Return 'NO MEMORY' Case $CAIRO_STATUS_INVALID_RESTORE Return 'INVALID RESTORE' Case $CAIRO_STATUS_INVALID_POP_GROUP Return 'INVALID POP GROUP' Case $CAIRO_STATUS_NO_CURRENT_POINT Return 'NO CURRENT POINT' Case $CAIRO_STATUS_INVALID_MATRIX Return 'INVALID MATRIX' Case $CAIRO_STATUS_INVALID_STATUS Return 'INVALID STATUS' Case $CAIRO_STATUS_NULL_POINTER Return 'NULL POINTER' Case $CAIRO_STATUS_INVALID_STRING Return 'INVALID STRING' Case $CAIRO_STATUS_INVALID_PATH_DATA Return 'INVALID PATH DATA' Case $CAIRO_STATUS_READ_ERROR Return 'READ ERROR' Case $CAIRO_STATUS_WRITE_ERROR Return 'WRITE ERROR' Case $CAIRO_STATUS_SURFACE_FINISHED Return 'SURFACE FINISHED' Case $CAIRO_STATUS_SURFACE_TYPE_MISMATCH Return 'SURFACE TYPE MISMATCH' Case $CAIRO_STATUS_PATTERN_TYPE_MISMATCH Return 'PATTERN TYPE MISMATCH' Case $CAIRO_STATUS_INVALID_CONTENT Return 'INVALID CONTENT' Case $CAIRO_STATUS_INVALID_FORMAT Return 'INVALID FORMAT' Case $CAIRO_STATUS_INVALID_VISUAL Return 'INVALID VISUAL' Case $CAIRO_STATUS_FILE_NOT_FOUND Return 'FILE NOT FOUND' Case $CAIRO_STATUS_INVALID_DASH Return 'INVALID DASH' Case $CAIRO_STATUS_INVALID_DSC_COMMENT Return 'INVALID DSC COMMENT' Case $CAIRO_STATUS_INVALID_INDEX Return 'INVALID INDEX' Case $CAIRO_STATUS_CLIP_NOT_REPRESENTABLE Return 'CLIP NOT REPRESENTABLE' Case $CAIRO_STATUS_TEMP_FILE_ERROR Return 'TEMP FILE ERROR' Case $CAIRO_STATUS_INVALID_STRIDE Return 'INVALID STRIDE' Case $CAIRO_STATUS_FONT_TYPE_MISMATCH Return 'FONT TYPE MISMATCH' Case $CAIRO_STATUS_USER_FONT_IMMUTABLE Return 'USER FONT IMMUTABLE' Case $CAIRO_STATUS_USER_FONT_ERROR Return 'USER FONT ERROR' Case $CAIRO_STATUS_NEGATIVE_COUNT Return 'NEGATIVE COUNT' Case $CAIRO_STATUS_INVALID_CLUSTERS Return 'INVALID CLUSTERS' Case $CAIRO_STATUS_INVALID_SLANT Return 'INVALID SLANT' Case $CAIRO_STATUS_INVALID_WEIGHT Return 'INVALID WEIGHT' Case $CAIRO_STATUS_INVALID_SIZE Return 'INVALID SIZE' Case $CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED Return 'USER FONT NOT IMPLEMENTED' Case $CAIRO_STATUS_DEVICE_TYPE_MISMATCH Return 'DEVICE TYPE MISMATCH' Case $CAIRO_STATUS_DEVICE_ERROR Return 'DEVICE ERROR' Case $CAIRO_STATUS_INVALID_MESH_CONSTRUCTION Return 'INVALID MESH CONSTRUCTION' Case $CAIRO_STATUS_DEVICE_FINISHED Return 'DEVICE FINISHED' Case $CAIRO_STATUS_LAST_STATUS Return 'LAST STATUS' Case Else Return 'UNKNOW ERROR' EndSwitch EndFunc ;==> _Cairo_status() Func _Cairo_status_to_string() Local $aRet = DllCall ( $h_CairoDll, 'str:cdecl', 'cairo_status_to_string' ) If @error Then Return SetError ( @error, 0, 0 ) ;~ If $aRet[0] = '<unknown error status>' Then Return '' Return $aRet[0] EndFunc ;==> _Cairo_status_to_string() Func _Cairo_surface_destroy ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_destroy', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_destroy() Func _Cairo_surface_finish ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_finish', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_finish() Func _Cairo_surface_write_to_png ( $pCairoSurface, $sFilePath ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_write_to_png', 'ptr', $pCairoSurface, 'str', $sFilePath ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_write_to_png() Func _GetBinaryType ( $sFilePath ) ; by Dougiefresh Local $hFile = FileOpen ( $sFilePath, 16 ) If $hFile = -1 Then Return SetError ( -1, 0, 'Invalid' ) If BinaryToString ( FileRead ( $hFile, 2 ) ) = 'MZ' Then FileSetPos ( $hFile, 60, 0 ) FileSetPos ( $hFile, Int ( FileRead ( $hFile, 4 ) ) +4, 0 ) Local $sFileRead = FileRead ( $hFile, 2 ) FileClose ( $hFile ) If $sFileRead = '0x6486' Then Return 'AMD64' If $sFileRead = '0x4c01' Then Return 'i386' If $sFileRead = '0x0002' Then Return 'IA64' EndIf FileClose ( $hFile ) Return 'Unknown' EndFunc ;==> _GetBinaryType() Func _Rsvg_handle_close ( $hRsvg ) Local $iError = 0 Local $aRet = DllCall ( $h_RsvgDll, 'ptr:cdecl', 'rsvg_handle_close', 'ptr', $hRsvg, 'int', $iError ) If @error Then Return SetError ( @error, 0, 0 ) If $iError Then Return SetError ( $iError, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_handle_close() Func _Rsvg_handle_get_dimensions ( $hRsvg ) Local $aSize[4], $tRsvgDimensionData = DllStructCreate ( 'int width;int height;double em;double ex' ) Local $aRet = DllCall ( $h_RsvgDll, 'int:cdecl', 'rsvg_handle_get_dimensions', 'ptr', $hRsvg, 'ptr', DllStructGetPtr ( $tRsvgDimensionData ) ) If @error Then Return SetError ( @error, 0, 0 ) $aSize[0] = $tRsvgDimensionData.width $aSize[1] = $tRsvgDimensionData.height $aSize[2] = $tRsvgDimensionData.em $aSize[3] = $tRsvgDimensionData.ex $tRsvgDimensionData = 0 Return $aSize EndFunc ;==> _Rsvg_handle_get_dimensions() Func _Rsvg_handle_new_from_file ( $sSvgFile ) If Not FileExists ( $sSvgFile ) Then Return SetError ( -1, 0, 0 ) Local $iError = 0 Local $aRet = DllCall ( $h_RsvgDll, 'ptr:cdecl', 'rsvg_handle_new_from_file', 'str', FileGetShortName ( $sSvgFile ), 'int', $iError ) If @error Then Return SetError ( @error, 0, 0 ) If $iError Then Return SetError ( $iError, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_handle_new_from_file() Func _Rsvg_handle_render_cairo ( $hRsvg, $pCr ) Local $aRet = DllCall ( $h_RsvgDll, 'bool:cdecl', 'rsvg_handle_render_cairo', 'ptr', $hRsvg, 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] ; Returns TRUE if drawing succeeded. EndFunc ;==> _Rsvg_handle_render_cairo() Func _Rsvg_init() ; deprecated since version 2.36 and should not be used in newly-written code. Local $aRet = DllCall ( $h_RsvgDll, 'int:cdecl', 'rsvg_init' ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_init() Script and files are available in the downloads Section
  5. Do not expect a SVG file as Sodipodi, Inkscape or Adobe Illustrator can generate. This "converter" doesn't actually trace or convert the image to vector. It just embed the bitmap image within an SVG container. #Region ;************ Includes ************ #Include <GDIPlus.au3> #Include <Memory.au3> #EndRegion ;************ Includes ************ Global $_B64E_CodeBuffer, $_B64E_CodeBufferMemory, $_B64E_Init, $_B64E_EncodeData, $_B64E_EncodeEnd Global $sFile, $hImage, $iW, $iH, $sType, $hFile, $sBase64String, $sFileRead, $sSvgPath, $sString _GDIPlus_Startup() $sFile = FileOpenDialog ( 'Select an Image', @DesktopDir, 'Images (*.jpg;*.png;*.gif;*.bmp)', 1+2 ) If @error Then Exit $sType = _FileGetType ( $sFile ) If @error Then ConsoleWrite ( '! File Type not supported, error : ' & @error & @Crlf ) Else $hFile = FileOpen ( $sFile, 16 ) If $hFile=-1 Then Exit MsgBox ( 262144+4096+16, 'Error', 'Can not Access this file.', 4 ) $hImage = _GDIPlus_ImageLoadFromFile ( $sFile ) $iW = _GDIPlus_ImageGetWidth ( $hImage ) $iH = _GDIPlus_ImageGetHeight ( $hImage ) _GDIPlus_ImageDispose ( $hImage ) $sFileRead = FileRead ( $hFile ) FileClose ( $hFile ) $sBase64String = _Base64Encode ( $sFileRead, 4000 ) $sString = '<svg' & @CRLF & _ ' version="1.1"' & @CRLF & _ ' xmlns="http://www.w3.org/2000/svg"' & @CRLF & _ ' xmlns:xlink="http://www.w3.org/1999/xlink"' & @CRLF & _ ' width="' & $iW & 'px" height="' & $iH & 'px"' & @CRLF & _ ' viewBox="0 0 ' & $iW & ' ' & $iH & '" preserveAspectRatio="none">' & @CRLF & _ ' <g>' & @CRLF & _ '<image width="' & $iW & '" height="' & $iH & '" xlink:href="data:image/' & $sType & ';base64,' & @CRLF & _ $sBase64String & @CRLF & _ '"/>' & @CRLF & _ ' </g>' & @CRLF & _ '</svg>' & @CRLF $sSvgPath = @TempDir & '\' & @HOUR & @MIN & @SEC & @MSEC & '-' & $iW & 'x' & $iH & '.svg' $hFile = FileOpen ( $sSvgPath, 1+2+8 ) If $hFile = -1 Then MsgBox ( 262144+4096+16, '', 'An error occurred whilst writing the temporary file.' ) Else FileWrite ( $hFile, $sString ) FileClose ( $hFile ) ShellExecute ( 'iexplore.exe', $sSvgPath ) EndIf EndIf _GDIPlus_Shutdown() Exit Func _FileGetType ( $sFilePath ) If Not FileExists ( $sFilePath ) Then Return SetError ( -1 ) If FileGetSize ( $sFilePath ) = 0 Then Return SetError ( 1, 0, 0 ) Local $hFile, $Binary, $Ret $hFile = FileOpen ( $sFilePath, 16 ) If $hFile = -1 Then Return SetError ( 3, 0, 0 ) $Binary = FileRead ( $hFile ) FileClose ( $hFile ) Local $sString = StringTrimLeft ( $Binary, 2 ) Local $sStringLeft = StringReplace ( StringTrimLeft ( StringLeft ( $Binary, 14 ), 2 ), '00', '' ) Local $sStringLeft12 = StringLeft ( $sStringLeft, 12 ) Local $sStringLeft8 = StringLeft ( $sStringLeft, 8 ) Local $sStringLeft4 = StringLeft ( $sStringLeft, 4 ) Select Case $sStringLeft12 = '474946383961' Or $sStringLeft12 = '474946383761' $Ret = 'GIF' Case $sStringLeft4 = 'FFD8' $Ret = 'JPG' Case $sStringLeft4 = '424D' $Ret = 'BMP' Case $sStringLeft8 = '89504E47' $Ret = 'PNG' Case Else Return SetError ( 2, 0, '' ) EndSelect If $Ret = 'GIF' Then StringReplace ( $sString, '0021F904', '0021F904' ) If @extended > 1 Then Return SetError ( 3, 0, '' ) ; animated gif. EndIf Return $Ret EndFunc ;==> _FileGetType() Func _Base64E_Exit() ; by Ward $_B64E_CodeBuffer = 0 _MemVirtualFree ( $_B64E_CodeBufferMemory, 0, $MEM_RELEASE ) EndFunc ;==> _Base64E_Exit() Func _Base64Encode ( $Data, $LineBreak=76 ) ; by Ward Local $State = _Base64EncodeInit ( $LineBreak ) Return _Base64EncodeData ( $State, $Data ) & _Base64EncodeEnd ( $State ) EndFunc ;==> _Base64Encode() Func _Base64EncodeData ( ByRef $State, $Data ) ; by Ward If Not IsDllStruct ( $_B64E_CodeBuffer ) Or Not IsDllStruct ( $State ) Then Return SetError ( 1, 0, '' ) $Data = Binary ( $Data ) Local $InputLen = BinaryLen ( $Data ) Local $Input = DllStructCreate ( 'byte[' & $InputLen & ']' ) DllStructSetData ( $Input, 1, $Data ) Local $OputputLen = Ceiling ( BinaryLen ( $Data )*1.4 )+3 Local $Output = DllStructCreate ( 'char[' & $OputputLen & ']' ) DllCall ( 'user32.dll', 'int', 'CallWindowProc', 'ptr', DllStructGetPtr ( $_B64E_CodeBuffer )+$_B64E_EncodeData, 'ptr', DllStructGetPtr ( $Input ), 'uint', $InputLen, 'ptr', DllStructGetPtr ( $Output ), 'ptr', DllStructGetPtr ( $State ) ) Return DllStructGetData ( $Output, 1 ) EndFunc ;==> _Base64EncodeData() Func _Base64EncodeEnd ( ByRef $State ) ; by Ward If Not IsDllStruct ( $_B64E_CodeBuffer ) Or Not IsDllStruct ( $State ) Then Return SetError ( 1, 0, '' ) Local $Output = DllStructCreate ( 'char[5]' ) DllCall ( 'user32.dll', 'int', 'CallWindowProc', 'ptr', DllStructGetPtr ( $_B64E_CodeBuffer ) + $_B64E_EncodeEnd, 'ptr', DllStructGetPtr ( $Output ), 'ptr', DllStructGetPtr ( $State ), 'int', 0, 'int', 0 ) Return DllStructGetData ( $Output, 1 ) EndFunc ;==> _Base64EncodeEnd() Func _Base64EncodeInit ( $LineBreak=76 ) ; by Ward If Not IsDllStruct ( $_B64E_CodeBuffer ) Then If @AutoItX64 Then Local $Opcode = '0x89C08D42034883EC0885D2C70100000000C64104000F49C2C7410800000000C1F80283E20389410C740683C00189410C4883C408C389C94883EC3848895C242848897424304889CB8B0A83F901742083F9024889D87444C6000A4883C001488B74243029D8488B5C24284883C438C30FB67204E803020000BA3D0000004080FE3F7F08480FBEF60FB614308813C643013D488D4303C643023DEBBC0FB67204E8D7010000BA3D0000004080FE3F7F08480FBEF60FB614308813C643013D488D4302EB9489DB4883EC68418B014863D248895C242848897424304C89C348897C24384C896424484C89CE83F80148896C24404C896C24504C897424584C897C24604C8D2411410FB6790474434D89C64989CD0F82F700000083F8024C89C5747B31C0488B5C2428488B742430488B7C2438488B6C24404C8B6424484C8B6C24504C8B7424584C8B7C24604883C468C34C89C54989CF4D39E70F840B010000450FBE374D8D6F014489F025F0000000C1F80409C7E8040100004080FF3FBA3D0000007F08480FBEFF0FB614384489F78855004883C50183E70FC1E7024D39E50F84B2000000450FB675004983C5014489F025C0000000C1F80609C7E8BD0000004080FF3FBA3D0000007F08480FBEFF0FB61438BF3F0000008855004421F74C8D7502E896000000480FBED70FB604108845018B460883C0013B460C89460875104C8D7503C645020AC7460800000000904D39E5742E410FBE7D004D8D7D01498D6E01E8560000004889FA83E70348C1EA02C1E70483E23F0FB60410418806E913FFFFFF4489F040887E04C7060000000029D8E9CCFEFFFF89E840887E04C7060200000029D8E9B9FEFFFF89E840887E04C7060100000029D8E9A6FEFFFFE8400000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F58C3' Else Local $Opcode = '0x89C08B4C24088B44240489CAC1FA1FC1EA1E01CAC1FA0283E103C70000000000C6400400C740080000000089500C740683C20189500CC2100089C983EC0C8B4C2414895C24048B5C2410897424088B1183FA01741D83FA0289D87443C6000A83C0018B74240829D88B5C240483C40CC210000FB67104E80C020000BA3D00000089F180F93F7F0989F20FBEF20FB6143088138D4303C643013DC643023DEBBD0FB67104E8DF010000BA3D00000089F180F93F7F0989F20FBEF20FB6143088138D4302C643013DEB9489DB83EC3C895C242C8B5C244C896C24388B542440897424308B6C2444897C24348B030FB6730401D583F801742D8B4C24488954241C0F820101000083F80289CF747D31C08B5C242C8B7424308B7C24348B6C243883C43CC210008B4C244889D739EF0F84400100008D57010FBE3F89542418894C241489F825F0000000C1F80409C6897C241CE8330100008B542418C644240C3D8B4C241489C789F03C3F7F0B0FBEF00FB604378844240C0FB644240C8D790188018B74241C83E60FC1E60239EA0F84CB0000000FB60A83C2018954241C89C825C0000000C1F80609C6884C2414E8D8000000BA3D0000000FB64C24148944240C89F03C3F7F0B0FBEF08B44240C0FB6143083E13F881789CEE8AD00000089F10FBED18D4F020FB604108847018B430883C0013B430C894308750EC647020A8D4F03C7430800000000396C241C743A8B44241C8B7C241C0FBE30894C241483C701E8650000008B4C241489F283E60381E2FC000000C1EA02C1E6040FB60410880183C101E9E4FEFFFF89F088430489C8C703000000002B442448E9B2FEFFFF89F189F8884B04C703020000002B442448E99CFEFFFF89F088430489C8C703010000002B442448E986FEFFFFE8400000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F58C3' EndIf $_B64E_Init = ( StringInStr ( $Opcode, '89C0' )-3 ) / 2 $_B64E_EncodeData = ( StringInStr ( $Opcode, '89DB' )-3 ) / 2 $_B64E_EncodeEnd = ( StringInStr ( $Opcode, '89C9' )-3 ) / 2 $Opcode = Binary ( $Opcode ) $_B64E_CodeBufferMemory = _MemVirtualAlloc ( 0, BinaryLen ( $Opcode ), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE ) $_B64E_CodeBuffer = DllStructCreate ( 'byte[' & BinaryLen ( $Opcode ) & ']', $_B64E_CodeBufferMemory ) DllStructSetData ( $_B64E_CodeBuffer, 1, $Opcode ) OnAutoItExitRegister ( '_Base64E_Exit' ) EndIf Local $State = DllStructCreate ( 'byte[16]' ) DllCall ( 'user32.dll', 'none', 'CallWindowProc', 'ptr', DllStructGetPtr ( $_B64E_CodeBuffer )+$_B64E_Init, 'ptr', DllStructGetPtr ( $State ), 'uint', $LineBreak, 'int', 0, 'int', 0 ) Return $State EndFunc ;==> _Base64EncodeInit() Thanks to Ward for his Base64 functions.
×
×
  • Create New...