Neatware Header
Home   Products   Solutions   Partners   Store   Company   

TclMagick Examples

  • Convert file format

    Convert file oldname to newname

    proc convert {oldname newname} {
      set wand [magick create wand]
      $wand ReadImage $oldname
      $wand WriteImage $newname
      magick delete $wand

    Call procedure

    convert sample.png sample.jpg
  • Annotation

    Load a png image, resize it and draw rotated text "MyrmecoX" over the image. Then save as the jpg, gif, and pdf files.

    Load the tclMagick package

    package require TclMagick

    Create wand & draw objects

    set wand [magick create wand]
    set draw [magick create draw]

    Load and resize a sample.png

    $wand ReadImage sample.png
    $wand ResizeImage 512 280 cubic

    Draw a red "MyrmecoX" rotated by 45 degree

    $draw push graph
      $draw SetStrokeWidth 1
      $draw SetStrokeColorString "red"
      $draw SetFillColorString "red"
      $draw SetFontSize 32
      $draw Annotation -97 170 "MyrmecoX"
    $draw pop graph
    $draw Rotate -45
    $wand DrawImage $draw

    Store the image in different file formats

    foreach ext {jpg gif pdf} {
      $wand WriteImage sample.$.ext

    Delete wand and draw objects

    magick delete $draw
    magick delete $wand