Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19

Thread: Batch files and Scripts

  1. #1
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default 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 Attached Files

  2. #2
    Moderator Sam_Zen's Avatar
    Join Date
    May 2007
    Location
    NL
    Posts
    1,896
    Version
    IrfanView 4.27
    OS
    Win XP Home SP1
    CPU Cores
    1

    Default

    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!

  3. #3
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default

    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 Thumbnails Attached Thumbnails Click image for larger version. 

Name:	batch dialog.png 
Views:	1210 
Size:	136.0 KB 
ID:	2106  
    Last edited by Mij; 21.10.2012 at 02:55 PM. Reason: Added update note

  4. #4
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default

    Quote 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 Attached Files
    Last edited by Mij; 04.11.2015 at 10:26 PM.

  5. #5
    Moderator Sam_Zen's Avatar
    Join Date
    May 2007
    Location
    NL
    Posts
    1,896
    Version
    IrfanView 4.27
    OS
    Win XP Home SP1
    CPU Cores
    1

    Default

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

  6. #6
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default

    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.

  7. #7
    Plugin Author
    Join Date
    Jun 2007
    Posts
    341
    OS
    Win 7 Professional SP1

    Default 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".
    
    >

  8. #8
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default

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

  9. #9
    Plugin Author
    Join Date
    Jun 2007
    Posts
    341
    OS
    Win 7 Professional SP1

    Default

    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;-)

  10. #10
    Professional User Mij's Avatar
    Join Date
    Mar 2007
    Location
    Camberley, Surrey, UK
    Posts
    2,763
    Version
    IrfanView 4.51
    OS
    32-bit Win 10
    CPU Cores
    3

    Default

    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 Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Imdib Helloworld.jpg 
Views:	626 
Size:	72.9 KB 
ID:	2191  

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •