set image [gd createFromGIF [open Tsq95.gif]] set imageSize [gd size $image] set imageWidth [lindex $imageSize 0] set imageHeight [lindex $imageSize 1] set aColorList [gd color get $image] set numColors [llength $aColorList] set aColor [lindex $aColorList [expr [llength $aColorList] / 2]] set junk [lvarpop aColor] ;# skip the index number set lastR [lvarpop aColor] set lastG [lvarpop aColor] set lastB [lvarpop aColor] # make a temp array of the color index values loop i 0 $numColors { set color [lvarpop aColorList] set index [lvarpop color] set r($index) [lvarpop color] set g($index) [lvarpop color] set b($index) [lvarpop color] } set i 0 set iLast [expr $imageWidth - 1] set j 0 set jLast [expr $imageHeight - 1] loop i 0 $iLast { loop j 0 $jLast { set index [gd get $image $i $j] set lastR [expr ($lastR + $r($index)) / 2] set lastG [expr ($lastG + $g($index)) / 2] set lastB [expr ($lastB + $b($index)) / 2] # This is the killer!! - probably doing a norm on each index set closest [gd color closest $image $lastR $lastG $lastB] gd set $image $closest $i $j } } image_expire 0 gd writeGIF $image $imageFile gd destroy $image