Tapatalk

Insert IMG sizes in HTML code via right click and running user tool

Insert IMG sizes in HTML code via right click and running user tool

5
NewbieNewbie
5

    Nov 29, 2016#1

    I am new to UEStudio and think it's great, but what I miss about my old editor is the ability to click on the regular (img - width + height) code, then on right click to select 'update IMG', which inserts the height and width pixels value in to the correct area.

    This was a real time saver for me and I'm looking for a way to do the same in UEStudio. I would be grateful if someone could help me do this via a tool or something else, but I'm not great at setting this kind of thing up.

    6,686587
    Grand MasterGrand Master
    6,686587

      Dec 02, 2016#2

      Well, it is possible to add or update width and height of an image element in active file by using a user tool which uses for example IrfanView or ImageMagick. But the solution depends on some requirements not posted by you. Therefore I can't yet offer the solution.
      • Solution using only a user tool

        This solution would use a user tool only which runs a batch file passing selected string to the batch file. The batch file runs the image application to get width and height and updates or adds the width and height of passed string, outputs the resulting string which replaces the selected string in active file.

        The requirements for this solution:
        • The image element attributes src, width and height must be all always on same line as it is not possible to pass a multi-line string to a batch file via command line parameter.
        • The src does not contain a URL encoded path/file name as it would be a lot of work for a simple batch file to URL decode the path/file name to get name of file on hard disk.
        • The user must always select src, width and height whereby the last two attributes must not exist.
      • Solution using a small UltraEdit macro and a user tool

        This solution would use the same user tool as first solution. The difference would be that the user must not select the image attributes. The macro would do it. All other requirements are identical to first solution.
      • Solution using an UltraEdit script and a user tool

        This solution would use an UltraEdit script which first determines src, width and height of image element in active file and if necessary URL decodes the path/file name, then runs a simple batch file via a user tool to get width of the image file and finally updates or adds width and height attributes of image element. This solution would be the most smart solution.

        The advantages of this solution in comparison to first and second solution are:
        • The image element attributes src, width and height must NOT be all on same line.
        • The src can contain also a URL encoded path/file name with for example %20 for a space character in path/file name which would be automatically decoded by the script before running the user tool.
        • In case of a URL encoded path/file name the script solution produces at least two instead of just one undo record.
      All 3 solutions would work without additional code in batch file only for image files which can be found on local hard disk with a path relative to path of active file. If the src contains a full qualified URL, additional tools would be needed in batch file to temporarily download the image file to hard disk to get width and height of the image.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Dec 02, 2016#3

        I suppose just the 'user tool' would be very helpful for me, although I'm not sure how I would implement it as I'm new to UES commands and tools - and might require some set-up instructions.

        6,686587
        Grand MasterGrand Master
        6,686587

          Dec 04, 2016#4

          I thought, selecting the attributes of img element in UE/UES, passing them to a batch file for adding or updating the values of attributes width and height would be more easier than writing the script code. Well, I was completely wrong. The Windows command processor limitations made this coding task really tricky. It would have been definitely better to use Visual Basic script or a PowerShell script for this task instead of a batch file with pure Windows internal commands. And best would have been to code the UltraEdit script for this task. However, I like tricky coding tasks. Therefore I finished the batch file coding even as I found out that coding a batch file for this task is not a good idea.

          The requirements I defined myself for this coding task before starting batch file coding:
          • HTML is case-insensitive and therefore processing the attributes of img element must be done also case-insensitive by the batch file.
          • Attribute values can be enclosed in double and single quotes and also not enclosed in quotes at all. All 3 quote types should be supported.
          • Attributes width and height not existing at all should be supported with appending the missing attribute(s) with correct value(s).
          • Attributes width and height existing already with no values should be supported, too.
          • Attributes width and height with empty values should be also supported by the batch file.
          • The order of the attributes should not matter on processing them by the batch file.
          • The whitespaces between the attributes can be any number of spaces or horizontal tabs.
          • The batch file does not need to keep the whitespace type (space or tab) and number of whitespaces between the attributes.
          • Leading and trailing whitespaces must not be kept by the batch file. The selected text must not start or end with whitespaces.
          • The batch file should work also if the passed arguments list starts with image file name without src=.
          • Other attributes in arguments lists should be processed without any modification.
          • URL encoded file names/paths must not be supported by the batch file.
          • Images on a web server referenced with complete URL must not be supported by the batch file.
          • Image elements with attributes spread over multiple lines must not be supported by the batch file solution.
          The test file I created for testing the batch file:

          Code: Select all

          <img src="gfx/image.png" alt="Test 1: no attributes width and height">
          <img src="gfx/image.png" width= height= alt="Test 2: attributes width and height with no values">
          <img src="gfx/image.png" width="" height="" alt="Test 3: attributes width and height with empty values in double quotes">
          <img src="gfx/image.png" width='' height='' alt="Test 4: attributes width and height with empty values in single quotes">
          <img src="gfx/image.png" width=400 height=50 alt="Test 5: attributes width and height with values without quotes">
          <img src="gfx/image.png" width="400" height="50" alt="Test 6: attributes width and height with values in double quotes">
          <img src='gfx/image.png' height='50' alt="Test 7: attributes width and height with values in single quotes">
          <img src='gfx/image.png' width='400'  height='50' alt="Test 8: attributes width and height 2 tabs and 2 spaces between">
          <img width=28 src="gfx/image.png" height='30' alt="Test 9: unusual order of the attributes and usual usage of quotes">
          <img src='gfx/image.png' alt="Test 10: attributes width and height wrong in % with other attributes between" hspace=5 style="border-style:ridge; border-width:10px; border-color:#A52A2A" width="400%" height="50%">
          
          Note: On line 8 there are two tabs and not multiple spaces as the browser displays left of width='400'. And there is one more tab character after width=28 on line 9.

          ATTENTION: This solution posted here works only with ANSI encoded HTML files. It does not work with Unicode (UTF-8) encoded HTML files with UE v23.20.0.43.

          The commented batch code using IrfanView as image processor which I stored in a file with name ImageWidthHeight.bat.

          Code: Select all

          @echo off
          setlocal EnableExtensions EnableDelayedExpansion
          
          rem Define file name of IrfanView with full path.
          set "IrfanView=%ProgramFiles(x86)%\IrfanView\i_view32.exe"
          
          rem Define type of quote to use around added or inserted width and
          rem height values. Possible values are " or ' or no quote at all.
          set "QuoteAdd=""
          
          rem Is the batch file called without any parameter?
          set "ArgsAll=%*"
          if "!ArgsAll!" == "" goto EndBatch
          
          rem Define some environment variables used later in batch code.
          set "TmpFile=%TEMP%\%~n0.tmp"
          set "ImgFile="
          set "ArgHeight=0"
          set "ArgWidth=0"
          set "ArgIndex=1"
          set "CharIndex=0"
          set "CharTab= "
          set "QuoteActive="
          set "QuoteDouble=""
          set "QuoteSingle='"
          goto NextArg
          
          
          rem Get all the arguments passed to the batch file. Windows command
          rem processor interprets space/tab and equal sign as argument delimiters.
          rem Therefore the arguments list must be parsed manually by batch code.
          
          :NextArg
          set "Argument="
          
          :ParseArg
          set "NextChar=!ArgsAll:~%CharIndex%,1!"
          set /A CharIndex+=1
          if "!NextChar!" == "" goto CheckArg
          if "!QuoteActive!" == "" (
              if "!NextChar!" == " " goto SkipSpaces
              if "!NextChar!" == "!CharTab!" goto SkipSpaces
              if !NextChar! == !QuoteDouble! (
                  set "QuoteActive=!QuoteDouble!"
              ) else if !NextChar! == !QuoteSingle! (
                  set "QuoteActive=!QuoteSingle!"
              )
          ) else if !QuoteActive! == !NextChar! (
              set "QuoteActive="
          )
          set "Argument=!Argument!!NextChar!"
          goto ParseArg
          
          rem Skip all spaces and tabs between two IMG attributes.
          
          :SkipSpaces
          set "NextChar=!ArgsAll:~%CharIndex%,1!"
          if "!NextChar!" == "" goto CheckArg
          if not "!NextChar!" == " " (
              if not "!NextChar!" == "!CharTab!" goto CheckArg
          )
          set /A CharIndex+=1
          goto SkipSpaces
          
          rem Once the argument string - IMG attribute without any value or with
          rem an empty value or with a non empty value - is determined by special
          rem parser, find out if attributes width and height are present already
          rem in arguments list without or with a value and get image file name
          rem with its relative path from the attribute src if present in the
          rem arguments list at all.
          
          rem If the current argument is the attribute src, it should be with the name
          rem of the image file with file extension and without or with a relative path.
          rem The image file name without or with path can be enclosed in double quotes
          rem or in single quotes which need to be removed from argument string.
          
          :CheckArg
          if "!Argument!" == "" goto CheckFile
          set "ArgNumber=0%ArgIndex%"
          set "ArgNumber=%ArgNumber:~-2%"
          
          if /I "!Argument:~0,6!" == "width=" goto EvalWidth
          if /I "!Argument:~0,7!" == "height=" goto EvalHeight
          if /I not "!Argument:~0,4!" == "src=" goto StoreArg
          set "ImgFile=!Argument:~4!"
          call :GetFileName
          
          :StoreArg
          set "ImgAttrib_%ArgNumber%=!Argument!"
          set /A ArgIndex+=1
          goto NextArg
          
          
          rem This is a subroutine to get image file name without surrounding quotes.
          
          :GetFileName
          if "!ImgFile:~0,1!" == "!QuoteDouble!" set "ImgFile=!ImgFile:~1!"
          if "!ImgFile:~-1!"  == "!QuoteDouble!" set "ImgFile=!ImgFile:~0,-1!"
          if "!ImgFile:~0,1!" == "!QuoteSingle!" set "ImgFile=!ImgFile:~1!"
          if "!ImgFile:~-1!"  == "!QuoteSingle!" set "ImgFile=!ImgFile:~0,-1!"
          goto :EOF
          
          
          rem The current argument is the attribute width. The next argument can be
          rem missing in case of just width= is at end of arguments list. In this case
          rem it is necessary to add the width value. But it is also possible that just
          rem width="" is in arguments list which must be updated by inserting the
          rem width value. Or there is just width='' or width= with a value to update.
          
          :EvalWidth
          if not "%ArgWidth%" == "0" goto StoreArg
          if "!Argument:~6!" == "" set "Argument=!Argument!%QuoteAdd%?%QuoteAdd%"
          set "ArgWidth=%ArgNumber%"
          goto StoreArg
          
          rem The current argument is the attribute height.
          rem It must be evaluated like the attribute width.
          
          :EvalHeight
          if not "%ArgHeight%" == "0" goto StoreArg
          if "!Argument:~7!" == "" set "Argument=!Argument!%QuoteAdd%?%QuoteAdd%"
          set "ArgHeight=%ArgNumber%"
          goto StoreArg
          
          
          rem Interpret first argument as file name if not attribute src with
          rem file name found in arguments list and remove surrounding quotes.
          
          :CheckFile
          if "!ImgFile!" == "" (
              set "ImgFile=!ImgAttrib_01!"
              call :GetFileName
          )
          if "!ImgFile!" == "" goto Output
          
          rem Replace all forward slashes by backslashes and get image
          rem file name with absolute path if the file really exists.
          set "ImgFile=!ImgFile:/=\!"
          if not exist "!ImgFile!" goto Output
          for %%I in ("!ImgFile!") do set "ImgFile=%%~fI"
          
          
          rem Run IrfanView to get information about image file.
          
          del "%TmpFile%" 2>nul
          if not exist "%IrfanView%" goto Output
          "%IrfanView%" "!ImgFile!" /info="%TmpFile%"
          if not exist "%TmpFile%" goto Output
          
          rem Find in image information the line with width and height.
          
          for /F "usebackq tokens=1-6" %%A in ("%TmpFile%") do (
              if /I "%%A %%B %%C %%E" == "Image dimensions = x" (
                  set "ImgWidth=%%D"
                  set "ImgHeight=%%F"
                  goto UpdateWidth
              )
          )
          
          rem IrfanView failed to get image information from file
          rem most likely because of file is not an image file.
          del "%TmpFile%"
          goto Output
          
          
          rem Keep the first 6 characters of width attribute and update
          rem the value with keeping the double or single quotes depending
          rem on what type of quotes are used for value of attribute width.
          
          rem The same is next done also for attribute height and image height.
          
          :UpdateWidth
          del "%TmpFile%"
          if "%ArgWidth%" == "0" goto AddWidth
          set "QuoteActive=!ImgAttrib_%ArgWidth%:~6,1!"
          if "!QuoteActive!" == "!QuoteDouble!" (
              set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!"%ImgWidth%""
          ) else if "!QuoteActive!" == "!QuoteSingle!" (
              set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!'%ImgWidth%'"
          ) else (
              set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!%ImgWidth%"
          )
          goto UpdateHeight
          
          rem But in case of attribute width was not in arguments list,
          rem append one more argument with the attribute width with the
          rem image width and quotes as defined at top of the batch file.
          
          :AddWidth
          set "ArgNumber=0%ArgIndex%"
          set "ArgNumber=%ArgNumber:~-2%"
          set "ImgAttrib_%ArgNumber%=width=%QuoteAdd%%ImgWidth%%QuoteAdd%"
          set /A ArgIndex+=1
          
          
          :UpdateHeight
          if "%ArgHeight%" == "0" goto AddHeight
          set "QuoteActive=!ImgAttrib_%ArgHeight%:~7,1!"
          if "!QuoteActive!" == "!QuoteDouble!" (
              set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!"%ImgHeight%""
          ) else if "!QuoteActive!" == "!QuoteSingle!" (
              set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!'%ImgHeight%'"
          ) else (
              set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!%ImgHeight%"
          )
          goto RebuildArgs
          
          :AddHeight
          set "ArgNumber=0%ArgIndex%"
          set "ArgNumber=%ArgNumber:~-2%"
          set "ImgAttrib_%ArgNumber%=height=%QuoteAdd%%ImgHeight%%QuoteAdd%"
          
          
          :RebuildArgs
          set "ArgsAll="
          for /F "tokens=1* delims==" %%I in ('set ImgAttrib_') do set "ArgsAll=!ArgsAll! %%J"
          set "ArgsAll=!ArgsAll:~1!"
          
          :Output
          echo !ArgsAll!
          
          :EndBatch
          endlocal
          
          Note 1: After IrfanView= the path and file name of IrfanView must be defined in the batch file.

          Note 2: The type of quote for added width and height values can be defined in the batch file after QuoteAdd=.

          Note 3: There must be a horizontal tab character after CharTab= in the batch file instead of the multiple spaces displayed by the browser according to HTML specification.

          The tool configuration for using this batch file is as follows.

          First tab Command:

          Menu item name: ImageWidthHeight
          Command line: "Path to\batch file\ImageWidthHeight.bat" %sel%
          Working directory: %p
          Toolbar bitmap/icon: empty or name of a suitable image file for this tool with full path

          Second tab Options:

          Program type: DOS program
          Save active file: NOT checked
          Save all files first: NOT checked

          Third tab Output:

          Command output: Append to existing
          Show DOS box: NOT checked
          Capture output: checked
          Replace selected text width: Captured output

          The user tool is now ready to use.

          The user must select the attributes src, width and height before running the user tool. src= must not be selected if the first string of selection is the image file name with relative path.

          As command echo outputs always a line with line termination, the selected string in file is replaced by updated string captured from batch file output with inserting also a line termination. So it is necessary to press key END and key DEL to delete the inserted line termination after tool execution.

          It is possible to run the user tool (batch file) also via an UltraEdit macro which makes the selection automatically and deletes the always inserted line termination.

          The code for this UltraEdit macro is:

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          IfSel
          RunTool "ImageWidthHeight"
          Key END
          Delete
          ExitMacro
          EndIf
          IfCharIs "<"
          Else
          Find Up "<"
          IfFound
          Key LEFT ARROW
          Else
          ExitMacro
          EndIf
          EndIf
          UnixReOff
          Find RegExp "img[^t ][~>^r^n]+"
          IfFound
          RunTool "ImageWidthHeight"
          Key END
          Delete
          EndIf
          
          See the forum topic How to create a macro from a posted macro code? with a step by step instruction on how to create a new macro with posted macro code.

          The macro should have the properties:

          Macro name: ImageWidthHeight
          Show cancel dialog for this macro: NOT checked
          Continue if search string not found: checked

          It is advisable on frequent usage to assign a hotkey or chord to this macro for quick execution by key(s).

          This macro should be also stored together with other often used macros in a macro file which is configured for being automatically loaded on startup of UltraEdit/UEStudio. This can be done on using Ribbon Mode by clicking on ribbon Advanced in group Macro on small arrow right to item Configure and clicking in popup menu on Set macro for auto-load. On using Toolbar/Menu Mode - Contemporary menus the configuration for automatic loading of a macro file on startup can be opened by clicking in menu Advanced in submenu Configure on menu item Set macro for auto-load. And last on using Toolbar/Menu Mode - Traditional menus clicking in menu Macro on Set Auto Load opens also the configuration for loading a macro file with 1 or more macros on startup of UltraEdit or UEStudio.

          This batch file solution with main code in batch file is definitely not the best solution as it turned out during developing the batch file. So I'm planning to write an UltraEdit script which adds/updates width and height values of an img element using IrfanView called via a batch file executed via a user tool from within the UltraEdit script. The UltraEdit script makes the hard job of identifying image file name with path and the width and height attributes.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Dec 04, 2016#5

            Thanks for taking the time to write this .bat code Mofi, I really appreciate your efforts.
            I have a few newbie questions before I start.

            1. Do I have to download IrfanView?

            2. Where do I place the ImageWidthHeight.bat file?

            3. Tried it, but got back.

            Code: Select all

            >
            '' is not recognized as an internal or external command,
            operable program or batch file.
            I must be doing something wrong.

            6,686587
            Grand MasterGrand Master
            6,686587

              Dec 05, 2016#6

              1. Yes, you have to download and install IrfanView because this application is needed to get width and height from image file.

              2. Wherever you want as you must specify in user tool configuration the batch file name with complete path.

              3. The error message is caused by saving the batch file code into a UTF-8 encoded file with BOM (byte order mark).

              Windows command processor does not support UTF-8 encoded files with BOM. Open the batch file in UltraEdit, use again Save As and this time select as encoding ASCII/ANSI and as line terminator DOS before saving the batch file with same name.
              Best regards from an UC/UE/UES for Windows user from Austria

              5
              NewbieNewbie
              5

                Dec 05, 2016#7

                Hi, Ive checked everything twice but still get a page full of odd Chinese characters after selection of (src, width and height) and invoking the tool.

                6,686587
                Grand MasterGrand Master
                6,686587

                  Dec 06, 2016#8

                  You forgot to mention an important detail. The HTML file opened in UltraEdit/UEStudio is a Unicode file, most likely UTF-8 encoded. My test HTML file was ANSI encoded.

                  The Unicode encoding of the HTML file causes a wrong replace of selected text by output of the batch file. The selected string is passed right to the batch file, but UltraEdit for Windows v23.20 and UEStudio v16.20 and all previous versions of UE/UES do not convert the captured output to Unicode before replacing the selected text resulting in garbage text.

                  It is most likely the first time that a user tool is called which outputs text using an OEM code page which directly should replace text in a Unicode file. I have reported this issue to IDM support by email as bug report.

                  I tried to workaround this issue with a macro with following code:

                  Code: Select all

                  InsertMode
                  ColumnModeOff
                  HexOff
                  IfCharIs "<"
                  Else
                  Find Up "<"
                  IfFound
                  Key LEFT ARROW
                  Else
                  ExitMacro
                  EndIf
                  EndIf
                  UnixReOff
                  Find RegExp "img[^t ][~>^r^n]+"
                  IfFound
                  Clipboard 9
                  Copy
                  NewFile
                  UnicodeToASCII
                  Paste
                  SelectToTop
                  RunTool "UpdateWidthHeight"
                  Key END
                  Delete
                  SelectToTop
                  Copy
                  CloseFile NoSave
                  Paste
                  ClearClipboard
                  Clipboard 0
                  EndIf
                  
                  But this does not work as the new file has no path and therefore %p in user tool configuration being essential is not correct replaced by path of HTML file and characters with a code point value greater 127 for example in attribute alt are destroyed by this workaround.

                  For that reason I must put you off to the UltraEdit/UEStudio scripting solution. The batch file solution doesn't work for Unicode encoded HTML files.
                  Best regards from an UC/UE/UES for Windows user from Austria

                  5
                  NewbieNewbie
                  5

                    Dec 06, 2016#9

                    Well, I suppose - even with my non existent scripting knowledge, I had an inkling this would be a little tricky.
                    Thanks for your help anyway Mofi,

                    6,686587
                    Grand MasterGrand Master
                    6,686587

                      Dec 07, 2016#10

                      It is possible to get also the batch file solution working for UTF-8 encoded HTML files with the limitation that selected string should not contain any character with a code point value greater U+007F, i.e. any non ASCII character, for example in alternate text of image element.

                      The solution is copying output of batch file to Windows clipboard and replace the selected text in active file by clipboard content. In this case UltraEdit makes the conversion from ANSI to Unicode before replacing the selected text in active file.

                      The required modifications in comparison to solution posted above replacing selected text with captured text:
                      • In the batch file the line

                        Code: Select all

                        echo !ArgsAll!
                        near end of batch file must be modified to

                        Code: Select all

                        echo !ArgsAll!|%SystemRoot%\System32\clip.exe
                      • In user tool configuration on tab Output the option Clipboard must be selected instead of Captured output.
                      • In UltraEdit macro (if used at all) the two occurrences of the two lines

                        Code: Select all

                        Key END
                        Delete
                        must be replaced twice by the single line

                        Code: Select all

                        Key BACKSPACE
                        The caret is at end of the text inserted from Windows clipboard after user tool execution instead of beginning of inserted text when the selected text is replaced by captured output.
                      clip.exe is a standard console application available since Windows Vista and Windows Server 2003. Users of Windows XP can copy clip.exe from Windows Server 2003 to Windows XP machine if having access to Windows Server 2003.

                      ATTENTION: This solution works for ANSI and Unicode encoded HTML files.

                      The commented batch code using IrfanView as image processor which I stored in a file with name ImageWidthHeight.bat.

                      Code: Select all

                      @echo off
                      setlocal EnableExtensions EnableDelayedExpansion
                      
                      rem Define file name of IrfanView with full path.
                      set "IrfanView=%ProgramFiles(x86)%\IrfanView\i_view32.exe"
                      
                      rem Define type of quote to use around added or inserted width and
                      rem height values. Possible values are " or ' or no quote at all.
                      set "QuoteAdd=""
                      
                      rem Is the batch file called without any parameter?
                      set "ArgsAll=%*"
                      if "!ArgsAll!" == "" goto EndBatch
                      
                      rem Define some environment variables used later in batch code.
                      set "TmpFile=%TEMP%\%~n0.tmp"
                      set "ImgFile="
                      set "ArgHeight=0"
                      set "ArgWidth=0"
                      set "ArgIndex=1"
                      set "CharIndex=0"
                      set "CharTab= "
                      set "QuoteActive="
                      set "QuoteDouble=""
                      set "QuoteSingle='"
                      goto NextArg
                      
                      
                      rem Get all the arguments passed to the batch file. Windows command
                      rem processor interprets space/tab and equal sign as argument delimiters.
                      rem Therefore the arguments list must be parsed manually by batch code.
                      
                      :NextArg
                      set "Argument="
                      
                      :ParseArg
                      set "NextChar=!ArgsAll:~%CharIndex%,1!"
                      set /A CharIndex+=1
                      if "!NextChar!" == "" goto CheckArg
                      if "!QuoteActive!" == "" (
                          if "!NextChar!" == " " goto SkipSpaces
                          if "!NextChar!" == "!CharTab!" goto SkipSpaces
                          if !NextChar! == !QuoteDouble! (
                              set "QuoteActive=!QuoteDouble!"
                          ) else if !NextChar! == !QuoteSingle! (
                              set "QuoteActive=!QuoteSingle!"
                          )
                      ) else if !QuoteActive! == !NextChar! (
                          set "QuoteActive="
                      )
                      set "Argument=!Argument!!NextChar!"
                      goto ParseArg
                      
                      rem Skip all spaces and tabs between two IMG attributes.
                      
                      :SkipSpaces
                      set "NextChar=!ArgsAll:~%CharIndex%,1!"
                      if "!NextChar!" == "" goto CheckArg
                      if not "!NextChar!" == " " (
                          if not "!NextChar!" == "!CharTab!" goto CheckArg
                      )
                      set /A CharIndex+=1
                      goto SkipSpaces
                      
                      rem Once the argument string - IMG attribute without any value or with
                      rem an empty value or with a non empty value - is determined by special
                      rem parser, find out if attributes width and height are present already
                      rem in arguments list without or with a value and get image file name
                      rem with its relative path from the attribute src if present in the
                      rem arguments list at all.
                      
                      rem If the current argument is the attribute src, it should be with the name
                      rem of the image file with file extension and without or with a relative path.
                      rem The image file name without or with path can be enclosed in double quotes
                      rem or in single quotes which need to be removed from argument string.
                      
                      :CheckArg
                      if "!Argument!" == "" goto CheckFile
                      set "ArgNumber=0%ArgIndex%"
                      set "ArgNumber=%ArgNumber:~-2%"
                      
                      if /I "!Argument:~0,6!" == "width=" goto EvalWidth
                      if /I "!Argument:~0,7!" == "height=" goto EvalHeight
                      if /I not "!Argument:~0,4!" == "src=" goto StoreArg
                      set "ImgFile=!Argument:~4!"
                      call :GetFileName
                      
                      :StoreArg
                      set "ImgAttrib_%ArgNumber%=!Argument!"
                      set /A ArgIndex+=1
                      goto NextArg
                      
                      
                      rem This is a subroutine to get image file name without surrounding quotes.
                      
                      :GetFileName
                      if "!ImgFile:~0,1!" == "!QuoteDouble!" set "ImgFile=!ImgFile:~1!"
                      if "!ImgFile:~-1!"  == "!QuoteDouble!" set "ImgFile=!ImgFile:~0,-1!"
                      if "!ImgFile:~0,1!" == "!QuoteSingle!" set "ImgFile=!ImgFile:~1!"
                      if "!ImgFile:~-1!"  == "!QuoteSingle!" set "ImgFile=!ImgFile:~0,-1!"
                      goto :EOF
                      
                      
                      rem The current argument is the attribute width. The next argument can be
                      rem missing in case of just width= is at end of arguments list. In this case
                      rem it is necessary to add the width value. But it is also possible that just
                      rem width="" is in arguments list which must be updated by inserting the
                      rem width value. Or there is just width='' or width= with a value to update.
                      
                      :EvalWidth
                      if not "%ArgWidth%" == "0" goto StoreArg
                      if "!Argument:~6!" == "" set "Argument=!Argument!%QuoteAdd%?%QuoteAdd%"
                      set "ArgWidth=%ArgNumber%"
                      goto StoreArg
                      
                      rem The current argument is the attribute height.
                      rem It must be evaluated like the attribute width.
                      
                      :EvalHeight
                      if not "%ArgHeight%" == "0" goto StoreArg
                      if "!Argument:~7!" == "" set "Argument=!Argument!%QuoteAdd%?%QuoteAdd%"
                      set "ArgHeight=%ArgNumber%"
                      goto StoreArg
                      
                      
                      rem Interpret first argument as file name if not attribute src with
                      rem file name found in arguments list and remove surrounding quotes.
                      
                      :CheckFile
                      if "!ImgFile!" == "" (
                          set "ImgFile=!ImgAttrib_01!"
                          call :GetFileName
                      )
                      if "!ImgFile!" == "" goto Output
                      
                      rem Replace all forward slashes by backslashes and get image
                      rem file name with absolute path if the file really exists.
                      set "ImgFile=!ImgFile:/=\!"
                      if not exist "!ImgFile!" goto Output
                      for %%I in ("!ImgFile!") do set "ImgFile=%%~fI"
                      
                      
                      rem Run IrfanView to get information about image file.
                      
                      del "%TmpFile%" 2>nul
                      if not exist "%IrfanView%" goto Output
                      "%IrfanView%" "!ImgFile!" /info="%TmpFile%"
                      if not exist "%TmpFile%" goto Output
                      
                      rem Find in image information the line with width and height.
                      
                      for /F "usebackq tokens=1-6" %%A in ("%TmpFile%") do (
                          if /I "%%A %%B %%C %%E" == "Image dimensions = x" (
                              set "ImgWidth=%%D"
                              set "ImgHeight=%%F"
                              goto UpdateWidth
                          )
                      )
                      
                      rem IrfanView failed to get image information from file
                      rem most likely because of file is not an image file.
                      del "%TmpFile%"
                      goto Output
                      
                      
                      rem Keep the first 6 characters of width attribute and update
                      rem the value with keeping the double or single quotes depending
                      rem on what type of quotes are used for value of attribute width.
                      
                      rem The same is next done also for attribute height and image height.
                      
                      :UpdateWidth
                      del "%TmpFile%"
                      if "%ArgWidth%" == "0" goto AddWidth
                      set "QuoteActive=!ImgAttrib_%ArgWidth%:~6,1!"
                      if "!QuoteActive!" == "!QuoteDouble!" (
                          set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!"%ImgWidth%""
                      ) else if "!QuoteActive!" == "!QuoteSingle!" (
                          set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!'%ImgWidth%'"
                      ) else (
                          set "ImgAttrib_%ArgWidth%=!ImgAttrib_%ArgWidth%:~0,6!%ImgWidth%"
                      )
                      goto UpdateHeight
                      
                      rem But in case of attribute width was not in arguments list,
                      rem append one more argument with the attribute width with the
                      rem image width and quotes as defined at top of the batch file.
                      
                      :AddWidth
                      set "ArgNumber=0%ArgIndex%"
                      set "ArgNumber=%ArgNumber:~-2%"
                      set "ImgAttrib_%ArgNumber%=width=%QuoteAdd%%ImgWidth%%QuoteAdd%"
                      set /A ArgIndex+=1
                      
                      
                      :UpdateHeight
                      if "%ArgHeight%" == "0" goto AddHeight
                      set "QuoteActive=!ImgAttrib_%ArgHeight%:~7,1!"
                      if "!QuoteActive!" == "!QuoteDouble!" (
                          set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!"%ImgHeight%""
                      ) else if "!QuoteActive!" == "!QuoteSingle!" (
                          set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!'%ImgHeight%'"
                      ) else (
                          set "ImgAttrib_%ArgHeight%=!ImgAttrib_%ArgHeight%:~0,7!%ImgHeight%"
                      )
                      goto RebuildArgs
                      
                      :AddHeight
                      set "ArgNumber=0%ArgIndex%"
                      set "ArgNumber=%ArgNumber:~-2%"
                      set "ImgAttrib_%ArgNumber%=height=%QuoteAdd%%ImgHeight%%QuoteAdd%"
                      
                      
                      :RebuildArgs
                      set "ArgsAll="
                      for /F "tokens=1* delims==" %%I in ('set ImgAttrib_') do set "ArgsAll=!ArgsAll! %%J"
                      set "ArgsAll=!ArgsAll:~1!"
                      
                      :Output
                      echo !ArgsAll!|%SystemRoot%\System32\clip.exe
                      
                      :EndBatch
                      endlocal
                      
                      Note 1: After IrfanView= the path and file name of IrfanView must be defined in the batch file.

                      Note 2: The type of quote for added width and height values can be defined in the batch file after QuoteAdd=.

                      Note 3: There must be a horizontal tab character after CharTab= in the batch file instead of the multiple spaces displayed by the browser according to HTML specification.

                      The tool configuration for using this batch file is as follows.

                      First tab Command:

                      Menu item name: ImageWidthHeight
                      Command line: "Path to\batch file\ImageWidthHeight.bat" %sel%
                      Working directory: %p
                      Toolbar bitmap/icon: empty or name of a suitable image file for this tool with full path

                      Second tab Options:

                      Program type: DOS program
                      Save active file: NOT checked
                      Save all files first: NOT checked

                      Third tab Output:

                      Command output: Append to existing
                      Show DOS box: NOT checked
                      Capture output: checked
                      Replace selected text width: Clipboard

                      The user tool is now ready to use.

                      The user must select the attributes src, width and height before running the user tool. src= must not be selected if the first string of selection is the image file name with relative path.

                      As command echo outputs always a line with line termination, the selected string in file is replaced by updated string captured from batch file output with inserting also a line termination. So it is necessary to press key BACKSPACE to delete the inserted line termination after tool execution.

                      It is possible to run the user tool (batch file) also via an UltraEdit macro which makes the selection automatically if there is currently no selection and deletes the always inserted line termination.

                      The code for this UltraEdit macro is:

                      Code: Select all

                      InsertMode
                      ColumnModeOff
                      HexOff
                      IfSel
                      RunTool "ImageWidthHeight"
                      Key BACKSPACE
                      ExitMacro
                      EndIf
                      IfCharIs "<"
                      Else
                      Find Up "<"
                      IfFound
                      Key LEFT ARROW
                      Else
                      ExitMacro
                      EndIf
                      EndIf
                      UnixReOff
                      Find RegExp "img[^t ][~>^r^n]+"
                      IfFound
                      RunTool "ImageWidthHeight"
                      Key BACKSPACE
                      EndIf
                      
                      See the forum topic How to create a macro from a posted macro code? with a step by step instruction on how to create a new macro with posted macro code.

                      The macro should have the properties:

                      Macro name: ImageWidthHeight
                      Show cancel dialog for this macro: NOT checked
                      Continue if search string not found: checked

                      It is advisable on frequent usage to assign a hotkey or chord to this macro for quick execution by key(s).

                      This macro should be also stored together with other often used macros in a macro file which is configured for being automatically loaded on startup of UltraEdit/UEStudio. This can be done on using Ribbon Mode by clicking on ribbon Advanced in group Macro on small arrow right to item Configure and clicking in popup menu on Set macro for auto-load. On using Toolbar/Menu Mode - Contemporary menus the configuration for automatic loading of a macro file on startup can be opened by clicking in menu Advanced in submenu Configure on menu item Set macro for auto-load. And last on using Toolbar/Menu Mode - Traditional menus clicking in menu Macro on Set Auto Load opens also the configuration for loading a macro file with 1 or more macros on startup of UltraEdit or UEStudio.
                      Best regards from an UC/UE/UES for Windows user from Austria