John Voltaire Maximo
John Voltaire Maximo

Reputation: 93

jpg to bmp without conversion tool

Can I change a jpg to bmp without using any conversion tool on a batch file? Upon checking this link

it appears I can't.

Upvotes: 0

Views: 121

Answers (1)

MC ND
MC ND

Reputation: 70943

If an hybrid batch/JScript.Net file is an option you can do something like

@if (@this)==(@isBatch) @end /* ------------------------------------------------
@echo off
    setlocal enableextensions disabledelayedexpansion
    rem Retrieve input parameters
    set "inputFile="  & for %%a in ("%~f1") do if /i "%%~xa"==".jpg" set "inputFile=%%~fa"
    set "outputFile=" & for %%a in ("%~f2") do if /i "%%~xa"==".bmp" set "outputFile=%%~fa"

    rem Check input parameters
    if not defined inputFile goto :usage
    if not defined outputFile goto :usage
    if not exist "%inputFile%" (
        echo Input file not found
        exit /b 2
    )

    rem Search JScript.Net compiler
    set "jsc=" & for /f "delims=" %%a in ('
        dir /b /s /a-d "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"
    ') do set "jsc=%%a"
    if not defined jsc (
        echo JScript.Net compiler not found 
        exit /b 3
    )

    rem Start hybrid to exe conversion
    call :launchConversion 
    exit /b %errorlevel%

:launchConversion 
    rem Try to compile current batch file JScript part
    for %%t in ("%temp%\%~nx0.%random%%random%%random%%random%.exe") do (
        rem If there is a collision, try again
        if exist "%%~ft" goto :launchConversion

        rem Try to compile and execute conversion
        "%jsc%" /nologo /out:"%%~ft" "%~f0" && "%%~ft"

        rem Remove exe file 
    ) & 2>nul del /q "%%~ft"
    rem Done
    endlocal & exit /b %errorlevel%

:showUsage
    echo Usage: %~n0 inputFile outputFile
    echo(
    exit /b 1

*/ //---------------------------------------------------------------------------
// JScript.Net part 

import System;
import System.Drawing;

    // Simply read input jpg file and save output bmp file 
    Image.FromFile( 
        System.Environment.GetEnvironmentVariable("inputFile")
    ).Save(
        System.Environment.GetEnvironmentVariable("outputFile")
        , System.Drawing.Imaging.ImageFormat.Bmp
    )

Upvotes: 1

Related Questions