Announcement

Collapse
No announcement yet.

Batch files and Scripts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Batch files and Scripts

    Over the years I have seen a number of Batch files (.bat) and Scripts (.vbs , .js , etc) posted for use with Irfanview. Most have been posted as replies to Support or Feature requests, so are difficult to find again even if they are still somewhere on the current forum.

    That is why I am starting this thread in the hope that those who have previously posted Batch files and Scripts that they think may be useful can record where they can be found and also somewhere to post any new ones.

    I will start the ball rolling by posting a Script. Its purpose is to replace entries in the Irfanview ini file. The idea is that you prepare small change files that contain lines that match those in the Irfanview file that you want to replace. The file "canvas1.ini" in the zip file is an example of one to change the width of the canvas margins. Those who use a command line with the Irfanview /batch option often complain because options such as these are not included in the dialog. This Script allows the values to be quickly changed before the /batch option is run.

    To use the "ini_replace.vbs" script file on its own you will first need to modify line 18 of the script using Notepad to record where the i_view32.ini file is located on your system (hopefully in the Appdata folder or another folder that has full read and write permissions). After doing that you can just drag and drop a change file onto the script file icon and the changes will be made. The script has lines (starting "wscript.echo ...") that will report on each change made. If you do not want that just put a ' at the start of those lines.

    You can also run the script from a batch file using the Cscript program included in Windows. The file "ini_replace.bat" is included as an example. With this you can specify where you have put the script file and where the ini file is. Then just drop the change file onto the ".bat" instead of the ".vbs". The reports then appear in the Command prompt window which is more convenient.

    Note that the replacement lines in the change files must be in exactly the same form as those in the original ini, including upper and lower case characters. Probably a good idea to make a backup copy of your ini file before you start playing, just in case!
    Attached Files

    #2
    A nice initiative.
    I'm not that familiar with vb or javascripts, but as far as *.bat files are concerned :
    I'm running TC , so I can launch a command line from anywhere, to do its job from a certain directory.

    This is only possible if the batchfile itself is at a position included in the system path.
    Of course one could place f.e. "change.bat" in the windoze system directory, but I don't like such a solution.
    I prefer to have as little 'alien' files as possible in dirs being part of the OS, to avoid an even bigger mess as it is now.

    In the DOS days I would make a seperate dir containing all my batch files, and added the dir in the autoexec to the path.
    Nowadays I use System Path Commander for this.

    I don't have any batchfiles directly related to IrfanView yet, but maybe these small utils could be useful anyway :

    1. A simple hex <---> decimal converter.
    Command "h2d 216A" to get '8554' or type "d2h 1022" to get '0x3FE'.
    2. A simple playlist generator.
    If you have directory with a album of music files of some format, it makes a basic *.m3u file suited for media players.
    Example command : "plist albumname extension ".
    0.6180339887
    Rest In Peace, Sam!

    Comment


      #3
      Don't forget that a shortcut works just as well as the file itself for launching a program. You can drop a file onto the shortcut and it gets passed to your .bat just as if it had been dropped directly onto it.

      To employ the ini_replace.bat file I posted that calls my script, I have put each of my change list files (what I call a "mini ini") into one folder and added a shortcut to ini_replace.bat there as well. I can then launch it from any drag and drop window that displays the folder. In Irfanview that includes the File Open, File Save and Look In dialog boxes.
      In the attached image I have just dragged Canvas2.ini onto the shortcut in the batch dialog "Look In" pane. That launched the bat file you can see and made the changes all without needing to close Irfanview.

      Update note : Current versions of Irfanview do allow canvas setting to be saved directly in the batch conversion dialog, so this script is no longer needed for that purpose. However there are many other cases when it proves useful.
      Attached Files
      Last edited by Mij; 21.10.2012, 03:55 PM. Reason: Added update note

      Comment


        #4
        Originally posted by Sam_Zen View Post
        A nice initiative.
        I'm not that familiar with vb or javascripts, but as far as *.bat files are concerned :
        I'm running TC , so I can launch a command line from anywhere, to do its job from a certain directory.
        .....
        Like me you appear to be mainly using batch files for the convenience of launching other applications from a Command line, Sam. I see that you just launch an exe file in your hex to decimal converter for example. The batch file simply serves as an interface.

        I was inspired though by that recent post by Foxy to try to use the power of the "For" function to create a batch file that would extract information from image files using the Irfanview \info and \fullinfo command line options and produce a table that could be opened as a spreadsheet in Excel - a little project that I have been thinking about for some time.

        I did not succeed in doing quite what I wanted, possibly because I am not really familiar enough with all you can do in a batch file these days. Instead I wrote another Visual basic script file to do it which I have attached if anyone is interested. I find that you can do everything in VBscript that you can with a batch file, and more, but it does have many more lines than the batch file does to do the same job.
        Attached Files
        Last edited by Mij; 04.11.2015, 11:26 PM.

        Comment


          #5
          A tutorial about batch programming can be found here
          0.6180339887
          Rest In Peace, Sam!

          Comment


            #6
            Thanks Sam. I have read several tutorials on batch programming. Some are quite good but if you look at Microsoft's own reference material, you quickly realize how much more there is that is not covered in them.

            It is the old problem. Until you know that you can do something, you never go looking for how to do it.

            Comment


              #7
              ImDIB - Handles DIBs and BMPs from the commandline

              I placed a small tool on our web site called ImDIB which may be helpful in batch programming. We are using it to create test files and to automate simple image editing. I touched it some days ago to demonstrate that there is a small problem with Irfanview pasting topdown DIBs from the clipboard (topdown DIBs are not common). Maybe it is useful for some of you. Tell us if you like to get enhancements.


              Code:
              >imdib /?
              Usage: imdib [command] {option} {operation} [file]
              Handles device independent bitmaps (DIBs and BMPs).
              Commands:
                /help          Show this help text.
                /copy          Copy new bitmap or bitmap from file  to clipboard.
                /paste         Paste bitmap from clipboard to file or show info.
                /new           Create new bitmap and save it to file or show info.
                /edit          Edit bitmap on clipboard or in file.
                /version       Show the version information of the executable.
              Options:
                /width=...     Sets the width of the bitmap in pixel (default: 640px)
                /height=...    Sets the height of the bitmap in pixel (default: 480px)
                /bitcount=...  Sets the size of a pixel (default: 24bits)
                /bitfields     Sets BI_BITFIELDS for bitcount 16 or 32 (default: BI_RGB)
                /gray          Sets the color table to gray colors
                /backcolor=... Sets background color (default: white 0xFFFFFF)
                /forecolor=... Sets foreground color (default: black 0x000000)
                /info          Show bitmap infos (default: don't show)
                /verbose       Be verbose during execution (default: silent)
                /pause         Pause after execution (default: don't pause)
              Operations:
                /topdown       Sets the bitmap type to topdown (default: bottomup)
                /bottomup      Sets the bitmap type to bottomup
                /dpm=...       Sets the resolution in dots per meter (default: 96dpi)
                  .hor=...     Sets horizontal resolution in dots per meter
                  .ver=...     Sets vertical resolution in dots per meter
                /dpi=...       Sets the resolution in dots per inch (default: 96dpi)
                  .hor=...     Sets horizontal resolution in dots per inch
                  .ver=...     Sets vertical resolution in dots per inch
                /select        Selects the whole bitmap
                  .shrink=...  Shrinks the selection by value (expand if < 0)
                  .move=...    Shrinks the selection by value
                  .left=...    Sets the left border of the selection
                  .right=...   Sets the right border of the selection
                  .top=...     Sets the top border of the selection
                  .bottom=...  Sets the bottom border of the selection
                  .width=...   Sets the width of the selection
                  .height=...  Sets the height of the selection
                /fill          Fills the selection
                  .color=...   Sets the color used for fill (-1: use forecolor; default: -1)
                /frame=...     Frames the selection using given width (outside if <0)
                  .color=...   Sets the color of frame (-1: use forecolor; default: -1)
                /text=...      Draw text aligned to the selection (default: no text)
                  .font=...    Sets the fontname used to draw text (default: Arial)
                  .size=...    Sets the fontsize used to draw text (default: 10pts)
                  .align=...   Sets the alignment in degrees (0: center; default: 0)
                  .color=...   Sets the color of text (-1: use forecolor; default: -1)
              Remarks:
                The default command is /paste. Only one command is allowed.
                Operations are handled between get and put of the bitmap.
                Multiple Operations are allowed. The order will be respected.
                Sub-operations like /text.color don't show their prefix in this help.
              Examples:
                imdib                   Paste bitmap from clipboard and show info.
                imdib /copy             Copy a bitmap created from defaults to clipboard.
                imdib /edit /bottomup   Make sure that the bitmap on clipboard is bottomup.
                imdib /new test.bmp     Store a bitmap created from defaults in "test.bmp".
              
              >

              Comment


                #8
                That looks very interesting Impdf. I will certainly give it a try when I have a spare moment.

                Comment


                  #9
                  Updated ImDIB to 1.07 to allow operation files which makes life easier ;-)

                  Here is an example from ImDIB_remarks.txt:

                  Operations may be stored in text files. The following is the content of the
                  operation file "add hello world.txt":

                  # Add the text "Hello World" with a border at the bottom right corner of the image
                  /select.shrink=5
                  /text.align=135
                  "/text=Hello World!"
                  /select.text
                  /select.shrink=-2
                  /frame=1

                  You may use this operation file to modify the content of the clipboard by calling:

                  imdib.exe "/edit=add hello world.txt"

                  or create a new image file:

                  imdib.exe /new /width=200 /height=100 "/more=add hello world.txt" test.bmp

                  You may call Irfanview from the command line. Ask to load an image and to copy it to the clipboard.
                  Then call imdib /edit... to change the clipboard content. And in the last step call Irfanview to paste the modified image from the clipboard and store it. This is the reason why ImDIB does not need to support more file tpes;-)

                  Comment


                    #10
                    Afraid I have not had much success with your "Hello world" example, impdf. My Windows Vista just crashes when I try to run it.
                    Attached Files

                    Comment


                      #11
                      Sorry for that. It's working on our Vista test bench, but this does not mean that it is not buggy.
                      Does it also die if you just call "imdib" or "imdib /copy"? You may also add a "/verbose" in front of the "/edit".
                      If you prefer we could shift the discussion to the private area of the forum so that this thread will not be miss-used.

                      Comment


                        #12
                        The ordinary copy and paste operations work fine. So far it is just the /edit= feature that is giving trouble. I will look at it more closely to see if I can tell where it goes wrong.

                        Yes, it would be better to move to the private area for detailed discussion.

                        Footnote for information: The problem was resolved in private discussion with impdf and the current version of the program does now work on my Vista machine.
                        Last edited by Mij; 22.07.2010, 05:50 PM. Reason: Added footnote

                        Comment


                          #13
                          Has anybody had trouble with pausing after a command line process complets? I use the command line to process PNG files but the command window allways closes after completion. It works, I would just like it to not close.

                          Comment


                            #14
                            If you are using Command prompt to run the command line then the Command prompt window will close when the action is complete. If you Call Irfanview then the Command prompt will wait for Irfanview to close before closing the window but if you want to keep the window open after that then you will have to write a batch file and add a Pause line after the Irfanview one.

                            e.g
                            Code:
                            "C:\program files\irfanview\i_view32.exe" "C:\users\me\*.tif" /convert="C:\users\him\*.jpg"
                            Pause

                            Comment


                              #15
                              This is in a batch file; only in DOS would these two seemingly equal commands not function the same. Thanks for the tip.



                              Code:
                              :: this line will exit the batch when complete no matter what so it is commented out
                              :: irfanview %~dp0\Panels\*.png /advanvedbatch /convert=%~dp0\RFIRM\*.png
                              
                              :: this line will proced to the next command and not exit the batch
                              "C:\program files\irfanview\i_view32.exe"  %~dp0\Panels\*.png /advanvedbatch /convert=%~dp0\RFIRM\*.png
                              
                              PAUSE
                              FYI
                              The %~dp0 tag allows this batch file to make use of the local directory structure. When the batch is executed it will look for the folders Panels and RFIRM in the folder that the batch file resides. It will convert all the raw PNG files in the Panels folder using the stored parameters for PNG to the RFIRM folder.

                              Comment

                              Working...
                              X