Announcement

Collapse
No announcement yet.

Command line - convert and save with the same name

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

    Command line - convert and save with the same name

    Is it possible to convert an image and save it with the same name to another directory? I mean I don't know the name of file (file to convert is choosen in Directory Opus (file manager) and I don't know exact name).
    I tried
    i_view32.exe {file} /resize=(80,60) /resample /convert={dir}\*.jpg
    but it didn't work.
    {file} is name of selected file (with absolute path)
    {dir} is current directory in file manager

    #2
    Yes, but it is far easier to use batch conversion/rename. If for some reason you still need a command line interface you could use variables in a batch file. You might try dragging-n-dropping the file on the batch file or shortcut to it.

    Here is a simple version allowing drag-n-drop input and typing the output:

    Code:
    @echo off
    set /p Path=Output Path:
    cd "C:\Program Files\IrfanView"
    i_view32.exe %1 /resize=(80,60) /resample /convert="%Path%\$N.jpg"
    exit
    This version is a bit more sophisticated with drag-n-drop or typed input and typed output, plus existence checking:

    Code:
    @echo off
    
    rem [The source path is passed from the send to function.]
    
    set Source=%~1
    if not "%~1"=="" goto output
    
    rem [Ask for source file.]
    
    :input
    set /p Source=Choose Source File Path:
    
    rem [Check if source exists.]
    
    if not exist "%Source%" (
    set input=1
    goto invalid
    )
    
    rem [Choose Output.]
    
    :output
    echo Convert "%Source%" to JPG
    echo.
    set /p Path=Output Path:
    
    rem [Check if output exists]
    
    set output=1
    if not exist "%Path%" goto invalid
    
    rem [Perform conversion.]
    
    cd "C:\Program Files\IrfanView"
    i_view32.exe" "%Source%" /resize=(80,60) /resample /convert="%Path%\$N.jpg"
    exit
    
    rem [Display message if no such path exists.]
    
    :invalid
    echo ----------------------------------------
    if "%input%"=="1" echo Sorry, but the directory "%Source%" does not exist.
    if "%output%"=="1" echo Sorry, but the directory "%Path%" does not exist.
    echo ----------------------------------------
    echo.
    set /p Restart=Try Again (y,n):
    if not "%Restart%"=="y" exit
    if "%input%"=="1" (
    set input=0
    goto :input
    )
    goto :output
    Test to make sure they work, or adjust as need be.

    Enjoy!
    Last edited by Skippybox; 09.01.2009, 04:21 PM.

    Comment


      #3
      Huh, finally I found some time to look into it again.

      Now command looks like this:
      "C:\Program Files\IrfanView\i_view32.exe" %1 /resize=(1024,768) /aspectratio /jpgq=90 /resample /convert="_converted\$N.jpg"
      Is it possible to prevent this script from enlarging small images. I want to leave alone images 100x100 or 150x200. Is it possible using command like this? Or should I search for /advancedbatch?

      Comment


        #4
        Using /advancedbatch would be best/easiest. It applies Advanced Batch Dialog options to the image (from INI file), so you probably will want to use an alternate INI from the program INI, to maintain your settings. So create the INI and also add /ini="Folder" to your command (where "Folder" is the folder containing the alternate INI).

        Advanced Batch does have a setting that resizes only large images. It can only filter out images smaller than what you are resizing to, so no specific size can be specified, if that is what you are looking for.

        Comment


          #5
          Actually, how to change the quality of images converted from jpeg/png/bmp files?
          "C:\Program Files\IrfanView\i_view32.exe" %1 /advancedbatch "/ini=d:\recent files\autohotkey" /convert=%2 /jpegq=1
          Adding /jpegq=nn doesn't work. Setting it in irfanview -> file -> batch -> options also doesn't affect batch conversion using commandline (but I would like to save quality value and use everytime the same value when using command line batch conversion)

          Comment


            #6
            Originally posted by daroc View Post
            Actually, how to change the quality of images converted from jpeg/png/bmp files?
            "C:\Program Files\IrfanView\i_view32.exe" %1 /advancedbatch "/ini=d:\recent files\autohotkey" /convert=%2 /jpegq=1
            Adding /jpegq=nn doesn't work. Setting it in irfanview -> file -> batch -> options also doesn't affect batch conversion using commandline (but I would like to save quality value and use everytime the same value when using command line batch conversion)
            You typed the switch name incorrectly. It is /jpgq=X, not /jpegq.

            Setting JPG Save Options from Batch Conversion should work, so long as you are modifying the correct INI. If you just run IrfanView and change it, the program INI will be updated, not your special one. You would need to make sure you start IrfanView with the special INI before modifying values. You can either start IrfanView with the /ini switch or drop a copy of the EXE in your special INI's folder to assist working on the INI.

            Also possible is to edit the INI yourself and type in section [JPEG]:

            Save Quality=80

            Comment

            Working...
            X