Version 3 of Image Magick

Updated 2006-04-12 18:47:11

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


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
    set lOWD [ pwd ]
    cd $gDir
    eval exec env convert.exe -depth $gDepth -size $gRows\x$gCols $gArgs $gFilNam $gFilNam\.jpg
    cd $lOWD
    WriteConf
  }

  proc ChooseFile {} {
  # select file to convert
    global gFilNam gDir
    set lFilNamL [ tk_getOpenFile -filetypes { { RAW { .gray .GRAY } } } -initialfile $gFilNam -initialdir $gDir ]
    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
    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 ]
    close $gConfFil
  }

  # default parameters
  set gDir "."
  set gFilNam ""
  set gRows 0
  set gCols 0
  set gDepth 8
  set gArgs ""
  # 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 -width 20 -anchor w -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
  label .sep -padx 2 -pady 2 -height 0
  button .bGO -text "Go" -command Gray2Jpeg -padx 2 -pady 2
  button .bEX -text "Exit" -command exit -padx 2 -pady 2

  # display
  wm resizable . 0 0
  grid .lf - - - - -sticky news
  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 .sep - - - - -sticky news
  grid x .bGO x .bEX x -sticky ew

  # start up
  if { [ expr { $argc > 0 } ] } {
    set gFilNam [ file tail [ lindex $argv 0 ] ]
    set gDir [ file dirname [ lindex $argv 0 ] ]
  }


Category Graphics