Richard Suchenwirth 2004-09-28 - Here's code for photo image rotation by +90 or -90 degrees only, but it runs reasonably fast:
proc imgrot90 {img {clockwise 0}} { set w [image width $img] set h [image height $img] set matrix [string repeat "{[string repeat {0 } $h]} " $w] if $clockwise { set x0 0; set y [expr {$h-1}]; set dx 1; set dy -1 } else { set x0 [expr {$w-1}]; set y 0; set dx -1; set dy 1 } foreach row [$img data] { set x $x0 foreach pixel $row { lset matrix $x $y $pixel incr x $dx } incr y $dy } set im2 [image create photo -width $h -height $w] $im2 put $matrix set im2 }
RS 2006-04-25: One frequently-asked-for feature is rotation of text, which can be done with the above code, plus the following:
proc rotext {w x y text} { package require Img raise [toplevel .tt] pack [label .tt.l -text $text] update idletasks set i0 [image create photo -data .tt.l] destroy .tt $w create image $x $y -image [imgrot90 $i0] image delete $i0 }
#--Testing demo, usage example:
pack [canvas .c -width 100 -height 80] update idletasks ;# to prevent occasional loss of the first item rotext .c 20 50 "Hello" rotext .c 50 50 "vertical world"
For fast arbitrary rotation (and scaling) see: Enhanced photo image copy command
Arts and crafts of Tcl-Tk programming | Category Image Processing