Sign in to follow this  
Followers 0
maqleod

basic command line image converter

1 post in this topic

#1 ·  Posted (edited)

as a little practice at command line apps I wrote a basic image converter. Seeing how it might be useful to some for something, I thought I'd post it.

gave it a more standardized format and added better error handling.

#include <GDIPlus.au3>

main()

Func main()
    validate()
    _GDIPlus_Startup()
    $image = _GDIPlus_ImageLoadFromFile($CmdLine[1])
    $clsid = _GDIPlus_EncodersGetCLSID(StringRight($CmdLine[2], 3))
    _GDIPlus_ImageSaveToFileEx($image, $CmdLine[2], $clsid)
    _GDIPlus_Shutdown()
    ConsoleWrite("Success.")
    Exit
EndFunc  ;==>main

Func validate()
    If $CmdLine[0] = 0 Or $CmdLine[1] = "-help" Then
        ConsoleWrite("supported file types are: bmp,gif,jpg,png,tif")
        ConsoleWrite(@CRLF & "usage: convert fileinput.xxx fileoutput.xxx")
        ConsoleWrite(@CRLF & "note: you must use exact extensions.")
        Exit
    ElseIf $CmdLine[0] > 2 Then
        ConsoleWrite("Error, too many arguments.")
        Exit
    ElseIf $CmdLine[0] < 2 Then
        ConsoleWrite("Error, too few arguments.")
        Exit
    ElseIf StringRight($CmdLine[1], 3) <> "bmp" And StringRight($CmdLine[1], 3) <> "gif" And StringRight($CmdLine[1], 3) <> "jpg" And StringRight($CmdLine[1], 3) <> "png" And StringRight($CmdLine[1], 3) <> "tif" Then
        ConsoleWrite("Error, cannot convert from that file type.")
        Exit
    ElseIf StringRight($CmdLine[2], 3) <> "bmp" And StringRight($CmdLine[2], 3) <> "gif" And StringRight($CmdLine[2], 3) <> "jpg" And StringRight($CmdLine[2], 3) <> "png" And StringRight($CmdLine[2], 3) <> "tif" Then
        ConsoleWrite("Error, cannot convert to that file type.")
        Exit
    ElseIf FileExists($CmdLine[1]) = 0 Then
        ConsoleWrite("Error, cannot find source file.")
        Exit
    EndIf
EndFunc  ;==>validate
Edited by maqleod

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0