Updated 2016-02-12 21:11:59 by tekbasse
What: TclMagick
Where: http://www.graphicsmagick.org/TclMagick/doc/ (was https://sourceforge.net/projects/graphicsmagick/ and before that: http://tclmagick.sourceforge.net/ )
Description: Tcl-only and/or Tk interface to GraphicsMagick library. Uses GraphicMagick's Wand-API. Provides a one to one mapping of the Wand API - requires no Tk to do image manipulation.
TclMagick README: http://www.graphicsmagick.org/TclMagick/doc/TclMagick.html (was https://sourceforge.net/p/graphicsmagick/code/ci/default/tree/TclMagick/README )
TkMagick README: http://www.graphicsmagick.org/TclMagick/doc/TkMagick.html
INSTALL: http://hg.code.sf.net/p/graphicsmagick/code/file/tip/TclMagick/INSTALL (was https://sourceforge.net/p/graphicsmagick/code/ci/default/tree/TclMagick/INSTALL )
Fully released according to GraphicsMagick release notes/News
Updated: 01/2016
Contact: See GraphicsMagick web site

What: TclWand
Where: http://members.shaw.ca/el_supremo/TclWand_053.zip
Description: Update from TclMagick 0.45 - this is a subset of the original TclMagick, in that it works with ImageMagick, but NOT with GraphicsMagick. This has only been compiled and tested on Windows XP Pro with ImageMagick 6.3.5 Q8.
Currently at version 0.0 .
Updated: 07/2007
Contact: See web site

2004/12/16 sheila A page on Building TclMagick would be helpful.

LV any feeling for when tclmagick and tkmagick will be stable enough for a formal release? tekbasse TclMagick has been adopted into the GraphicsMagick library. Earliest "news worthy" improvement was 28 April 2012: http://www.graphicsmagick.org/NEWS.html#april-28-2012

2004/11/18 sheila I love these extensions and I hope a formal release comes soon. The few crashes and build problems I had were solved very quickly after I asked the developers for help.

Sheila, did you get a successful build of Tkmagick for windows? If so could you mail me the .dll or post it somewhere? Thanks RT

sheila Yes, I did. Let me see about making it available and/or the VC++ project files. What type of build problems did you have?

RT Got it compiled and linked but the result crashed when a command was invoked (This more than a few months ago). Perhaps it was mislinked. I did build TclMagick OK after modifying its project file. I would be like to get both the .dll and the "make" file if you can share.

sheila aha, I had similar problems. The project files have been updated in CVS since then. One root cause of my problem was that the TkMagick was including TclMagick.c in it's project file rather than linking to the TclMagick DLL. This caused TclMagick to be loaded twice when I would package require TclMagick and TkMagick at the same time. I don't know if this is your root cause.

Here are my files http://feafaroth.org/tcl/ caveat emptor. Obviously to use these you'll need to hack out my paths.

Rolf Schroedter provides this example of the extension:
# Load the tclMagick module
load TclMagick.dll

# Create wand & draw objects
set wand [magick::wand create]
set draw [magick::draw create]

# Load & enlarge a PNG
$wand ReadImage sample.png
$wand ResizeImage 500 500 cubic
# Draw a red "Tcl/Tk" rotated by 45<B0>
$draw push graph
    $draw SetStrokeWidth 1
    $draw SetStrokeColorString "red"
    $draw SetFillColorString "red"
    $draw SetFontSize 18
    $draw Annotation -97 170 "Tcl/Tk"
$draw pop graph
$draw Rotate -45

$wand DrawImage $draw

# Write the image in different file formats
$wand WriteImage sample.jpg
$wand WriteImage sample.gif
$wand WriteImage sample.pdf

# Delete wand & draw objects
magick::draw delete $draw
magick::wand delete $wand

This extension is tracking an unstable version of ImageMagick (CVS, basically). I have an updated version for the latest out of CVS that now also compiles on Linux. Hopefully, TclMagick will be included in ImageMagick itself at some point. - davidw

davidw: I am working on making code that will link the Tcl imagemagick code with Tk. Although of course you do not and should not need Tk to use the TclMagick extension! You don't need a display to process images.

... For now it's just going to be a command to transfer preexisting Tk images to preexisting ImageMagick "wand"'s, and vice versa. In the future, I'd like to allow for tighter integration ala Img.

elfring 2003-12-01 Would you like to get a canvas to work with the [Wand API] [1]?

The TkMagick extension is also built with TclMagick, and you can use it to transfer Magick images to Tk images.

ES: This looks very useful, but I can't get the code! The suggested anonymous CVS command on the home page returns the following:
 cvs -d:pserver:[email protected]:/GraphicsMagick co TclMagick
 cvs checkout: warning: failed to open /home/edsuom/.cvspass for reading: No such file or directory
 cvs checkout: authorization failed: server cvs.graphicsmagick.org rejected access to /GraphicsMagick for user anonymous
 cvs checkout: used empty password; try "cvs login" with a real password

davidw: Oops, requires you to first run 'login' with password anonymous. The web page is updated now in any case, and I will remove these comments in a week or so.

2004/11/18 sheila I've been learning TclMagick and TkMagick, and I figured I'd share some of my fumblings here in case it helps anyone else. The documentation is spare, and I'd like to perhaps make some pages for all of the commands if that is okay for this wiki.

One of the first puzzlers was cropping behavior.

The ImageMagick documentation that I found says that a crop will keep the part of the picture in the crop, preserving its location on the canvas, but this is not what I found when I attempted to try this on my own.

 Notice that the size of the displayed image has not been effected by
 the "-crop" operation. The actual image itself has been cropped, but
 the canvas on which the GIF image is displayed is still the same size
 as the original canvas. Though the position of the cropped image
 matches that of the original image.

Here's an ascii rendition of what I saw and what I expected.
     beginning image
   |   image        |
   |  +----+        |
   |  |crop|        |
   |  |    |        |
   |  +----+        |
   |                |
   cropped section
   |crop|   unexpected canvas
   |    |

     Overlay operation

      unexpected behavior    expected behavior
    +----+ ----------+       +----------------+
    |crop|           |       |   image2       |
    |    |           |       |  +----+        |
    +----+           |       |  |crop|        |
    |     image2     |       |  |    |        |
    |                |       |  +----+        |
    |                |       |                |
    +----------------+       +----------------+

Here is a simple .tcl file I made to play around with this.
package require Tk
package require TclMagick
package require TkMagick

proc test_crop {} {

    set red_wand [magick create wand]
    set yellow_wand [magick create wand]

    $red_wand ReadImage red.png
    $yellow_wand ReadImage yellow.png

    # select arbitrary crop dimensions
    set width [expr [$yellow_wand width] - 100]
    set height [expr [$yellow_wand height] - 100]
    # crop a section away from the origin
    $yellow_wand crop $width $height 50 50

    # overlay the cropped result onto the red wand
    $red_wand composite $yellow_wand over

    # change to photo
    set composite_photo [image create photo]
    magicktophoto $red_wand $composite_photo

    # draw on canvas
    canvas .c
    .c create image 0 0 -image $composite_photo -anchor nw -tag crop
    grid .c

proc clean_magick {} {
    # free all of the magick objects
    foreach mobj [magick names] {
        magick delete $mobj

console show

(launch and type test_crop to see the unexpected behavior)

2004/11/19 sheila correction: I received a reply from the TclMagick mailing list explaining that the documentation I read is based on the command line interface for ImageMagic, and TclMagick is based on the C API for ImageMagick. The functionality is not quite the same.

This was an interesting exploration for me. To get what I want, I will play around with compositions. ...off to work!

(I dumped my png files into http://feafaroth.org/png/yellow.png and http://feafaroth.org/png/red.png)

2004/11/19 sheila The composition to get what I expected isn't complicated at all. I only have to provide an x and y offset to the composite command. e.g. modify the composite command for the purpose of this example to:
 $red_wand composite $yellow_wand over 50 50

2004/12/01 sheila

Why does the wand change from a 24 bit wand to a 32 bit wand when I draw on it?
set 24wand1 [magick create wand]
set 24wand2 [magick create wand]

$24wand1 ReadImage 24one.bmp
$24wand2 ReadImage 24two.bmp
$24wand1 composite $24wand2 difference
# this results in 24 bit depth image
$24wand1 WriteImage test.bmp

set pixel [magick create pixel]
set draw [magick create drawing]

$pixel color white
$draw fillcolor $pixel
$draw rectangle 0 0 50 50
$24wand1 DrawImage $draw
# this results in 32 bit depth image
$24wand1 WriteImage test2.bmp

bmp files at http://starkravingsane.org/tcl/

I ran into the problem while trying to use CompareImage, and I did not realize that my drawn-on image had changed bit depth.

Both are 24 bit depth
$24wand1 CompareImages $24wand2 meansquarederror

unexpected conversion of 24wand1 to 32 bit depth after DrawImage. oops.
$24wand1 CompareImages $24wand2 meansquarederror

How do I force draw not to change the bit depth?

sheila Update: The wand that has a drawing has an opacity channel which it did not have before.

2010-10-18 ALX

Code Snippet: Convert: First page of a PDF to jpeg, resize and set to 72 dpi
package require TclMagick

set w [magick create wand]

$w read ./mydoc.pdf\[0\]

set width 180
# calculate to preserve aspect ratio
set height [expr {int ([$w height] * $width / [$w width])}]
$w resize $width $height]

$w resolution 72

$w write mypict.jpg
magick delete $w

[vinniyo] - 2013-11-15 22:49:51

make sure to set font on Windows eg $draw SetFont "<FONT>" for Annotation or you will get nothing.
lappend auto_path C:/Tcl/lib
package require TclMagick

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

$wand ReadImage sample-in.jpg

[magick create pixel pix] SetColor "blue"
$draw push graph
    $draw SetStrokeWidth 1
    $draw SetStrokeColor pix
    $draw SetFillColor pix
    $draw SetFontSize 32
    $draw SetFont "Arial"
    $draw Annotation 20 50 "Hello world"
$draw pop graph

$wand DrawImage $draw
$wand WriteImage sample-out.jpg

magick delete $draw
magick delete $wand

[vinniyo] - 2013-12-17 05:19:20

Anyone know how to overlay two images and have control over the opacity?
set wand [magick create wand]
set wand2 [magick create wand]
$wand ReadImage 1.jpg
$wand2 ReadImage 2.jpg

$wand composite $wand2 overlay

$wand WriteImage out2.jpg

I need to have different frames with 10%, 20% etc transparency.