Version 4 of Quick photo rotation

Updated 2006-01-11 17:35:58

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
 }

For fast arbitrary rotation (and scaling) see: Enhanced photo image copy command

Arts and crafts of Tcl-Tk programming


Category Image Processing