See also TclMagickNetpbm offers much the same functionality as ImageMagick in regard to conversion between formats. Both are open-sourced.PR Here's an example how I use Tcl/Tk with ImageMagick to convert RAW grayscale images to JPEG. I'm calling this script from a BAT file, see Droplets.Gray2Jpeg.tcl
#!env wish
proc Gray2Jpeg {} {
# the command line to execute
global gFilNam gDir gRows gCols gDepth gArgs gKeep
set lOWD [ pwd ]
cd $gDir
eval exec env convert.exe -depth $gDepth -size $gRows\x$gCols $gArgs GRAY:$gFilNam [ file rootname $gFilNam ].jpg
cd $lOWD
WriteConf
if { $gKeep == 0 } { exit }
}
proc ChooseFile {} {
# select file to convert
global gFilNam gDir
set lFilNamL [ tk_getOpenFile -filetypes { { RAW { .gray .raw } } } \
-initialfile $gFilNam -initialdir $gDir ]
if { [ string length $lFilNamL ] > 0 } {
set gFilNam [ file tail $lFilNamL ]
set gDir [ file dirname $lFilNamL ]
WriteConf
}
}
proc WriteConf {} {
# write conf file
global env gFilNam gDir gConfFil gRows gCols gDepth gArgs gKeep
set gConfFil [ open [ file join $env(HOME) ".Gray2Jpeg.tcl.conf" ] "w" ]
puts $gConfFil [ list set gDir $gDir ]
puts $gConfFil [ list set gFilNam $gFilNam ]
puts $gConfFil [ list set gRows $gRows ]
puts $gConfFil [ list set gCols $gCols ]
puts $gConfFil [ list set gDepth $gDepth ]
puts $gConfFil [ list set gArgs $gArgs ]
puts $gConfFil [ list set gKeep $gKeep ]
close $gConfFil
}
# default parameters
set gDir "."
set gFilNam ""
set gRows 0
set gCols 0
set gDepth 8
set gArgs ""
set gKeep 0
# get parameters from conf file
catch { source [ file join $env(HOME) ".Gray2Jpeg.tcl.conf" ] }
# build window
labelframe .lf -text "Raw Gray Image" -padx 2 -pady 2
label .lf.l11 -text "Filename: " -padx 2 -pady 2
label .lf.l12 -textvariable ::gFilNam -relief sunken -bd 1 -width 20 -anchor e -padx 2 -pady 2
button .lf.b13 -text "..." -command ChooseFile -bd 1 -padx 2 -pady 2
label .lf.l21 -text "Rows: " -padx 2 -pady 2
entry .lf.e23 -textvariable ::gRows -width 5 -justify right
label .lf.l31 -text "Columns: " -padx 2 -pady 2
entry .lf.e33 -textvariable ::gCols -width 5 -justify right
label .lf.l41 -text "Depth: " -padx 2 -pady 2
entry .lf.e43 -textvariable ::gDepth -width 5 -justify right
label .lf.l51 -text "Arguments: " -padx 2 -pady 2
entry .lf.e52 -textvariable ::gArgs
frame .f
checkbutton .f.cb -variable ::gKeep
label .f.l -text "Keep Open" -bd 0 -font { { system } 7 }
button .bOK -text " OK " -command Gray2Jpeg -padx 2 -pady 2
button .bEX -text "Cancel" -command exit -padx 2 -pady 2
# display
wm resizable . 0 0
grid .lf.l11 .lf.l12 .lf.b13 -sticky ew
grid .lf.l21 x .lf.e23 -sticky ew
grid .lf.l31 x .lf.e33 -sticky ew
grid .lf.l41 x .lf.e43 -sticky ew
grid .lf.l51 .lf.e52 - -sticky ew
grid .lf - - - - - - -sticky news
grid .f x x .bEX x .bOK x -sticky news
grid .f.l .f.cb
# start up
if { $argc > 0 } {
set gFilNam [ file tail [ lindex $argv 0 ] ]
set gDir [ file dirname [ lindex $argv 0 ] ]
}
#console showSee also imgop, Tcl/Tk Identify

