Version 9 of Image Magick

Updated 2006-10-31 22:52:34

Windows/Linux command line tools and C libs to do image manipulation. Very powerful. Very fast. Deliciously bug-free. Open source.

See http://www.imagemagick.org/

See also TclMagick

Netpbm 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 show

The imgop library available at [L1 ] provides a number of routines to operate on Tk images and also to call ImageMagick for some basic operations on pictures. The library tries to abstract away the difference between file (names) and existing Tk images, while always returning Tk images ready to be used in your application. imgop is far from a replacement for TclMagick, it has simply grown out of a number of routines that I had here and there, in applications where I did not want to link in the whole TclMagick. Note that ImageMagick now comes with an ActiveX component, which would offer yet another way to interface it, via tcom for example. EF


Category Graphics