no display name and no $DISPLAY environment variable
    while executing
"load /enadisk/commun/linux/local/ActiveTcl-8.6.11/lib/libtk8.6.so Tk"
    ("package ifneeded Tk 8.6.11" script)
    invoked from within
"package require Tk"
    (in namespace eval "::iredexp" script line 4)
    invoked from within
"namespace eval ::iredexp \
	{
    namespace export expand expand2
    
    package require Tk
    package require Img
    
    # expand without transp..."
    (in namespace eval "::request" script line 3)
    invoked from within
"namespace eval ::request $script"
    ("::try" body line 12)

OUTPUT BUFFER:

#!/usr/local/bin/wish namespace eval ::iredexp \ { namespace export expand expand2 package require Tk package require Img # expand without transparency proc expand {image coef} \ { # check coef if {$coef < 1.0} \ { error "bad coef \"$coef\": should not be less than 1.0" } if {$coef - int($coef) < 1.e-4} \ { return [optim $image [expr {int($coef)}]] } # get the old image content set width [image width $image] set height [image height $image] if {$width * $height == 0} { error "bad image" } # create corresponding planes for {set y 0} {$y < $height} {incr y} \ { set r:row {} set g:row {} set b:row {} for {set x 0} {$x < $width} {incr x} \ { foreach {r g b} [$image get $x $y] break foreach c {r g b} { lappend $c:row [set $c] } } foreach c {r g b} { lappend $c:data [set $c:row] } } # compute the new image content set Width [expr {round($width * $coef)}] set Height [expr {round($height * $coef)}] set ey 0 set y2 0 set cy2 $Height for {set Y 0} {$Y < $Height} {incr Y} \ { set r:Row {} set g:Row {} set b:Row {} # y1 is the top coordinate in the old image set y1 $y2 set cy1 [expr {$Height - $cy2}] incr ey $height set y2 [expr {$ey / $Height}] set cy2 [expr {$ey % $Height}] if {$y1 == $y2} { set cy1 $cy2 } set ex 0 set x2 0 set cx2 $Width for {set X 0} {$X < $Width} {incr X} \ { set x1 $x2 set cx1 [expr {$Width - $cx2}] incr ex $width set x2 [expr {$ex / $Width}] set cx2 [expr {$ex % $Width}] if {$x1 == $x2} { set cx1 $cx2 } # compute pixel foreach c {r g b} { set $c 0; set _$c 0 } for {set y $y1} {$y <= $y2} {incr y} \ { # compute y coef switch $y \ $y1 { set cy $cy1 } \ $y2 { set cy $cy2 } \ default { set cy $height } if {$cy == 0} { continue } if {$cy > $height} { set cy $height } for {set x $x1} {$x <= $x2} {incr x} \ { # compute x coef switch $x \ $x1 { set cx $cx1 } \ $x2 { set cx $cx2 } \ default { set cx $width } if {$cx == 0} { continue } if {$cx > $width} { set cx $width } # weight each initial pixel by cx & cy set cxy [expr {$cx * $cy / double($width) / $height}] foreach c {r g b} \ { set comp [lindex [set $c:data] $y $x] incr $c [expr {round($comp * $cxy)}] set _$c [expr {[set _$c] + $cxy}] } } } set _ {} foreach c {r g b} \ { set comp [set $c] if {$comp > 255} { set comp 255 } lappend $c:Row $comp lappend _ [set _$c] } } foreach c {r g b} { lappend $c:Data [set $c:Row] } } # crisping for {set Y 0} {$Y < $Height} {incr Y} \ { set Row {} for {set X 0} {$X < $Width} {incr X} \ { if {$X == 0 || $X == $Width - 1 || $Y == 0 || $Y == $Height - 1} \ { foreach c {r g b} { set $c [lindex [set $c:Data] $Y $X] } } \ else \ { foreach c {r g b} \ { set c00 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 1}]] set c01 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 0}]] set c02 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X + 1}]] set c10 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 1}]] set c11 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 0}]] set c12 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X + 1}]] set c20 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 1}]] set c21 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 0}]] set c22 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X + 1}]] set cc [expr {int(1.4 * $c11 - 0.05 * ($c00 + $c01 + $c02 + $c10 + $c12 + $c20 + $c21 + $c22))}] if {$cc < 0} { set cc 0 } if {$cc > 255} { set cc 255 } set $c $cc } } lappend Row [format #%02x%02x%02x $r $g $b] } lappend Data $Row } # create the new image set Image [image create photo] # fill the new image $Image put $Data # return the new image return $Image } # integral expand proc optim {image coef} \ { set coef [expr {int($coef)}] if {$coef == 1} { return $image } set width [image width $image] set height [image height $image] set data [$image data] set data2 {} for {set y 0} {$y < $height} {incr y} \ { set row [lindex $data $y] set row2 {} for {set x 0} {$x < $width} {incr x} \ { set pixel [lindex $row $x] for {set i 0} {$i < $coef} {incr i} \ { lappend row2 $pixel } } for {set j 0} {$j < $coef} {incr j} \ { lappend data2 $row2 } } set image2 [image create photo] $image2 put $data2 return $image2 } # expand with transparency proc expand2 {image coef} \ { # check coef if {$coef < 1.0} \ { error "bad coef \"$coef\": should not be less than 1.0" } if {$coef - int($coef) < 1.e-4} \ { return [optim $image [expr {int($coef)}]] } # get the old image content set width [image width $image] set height [image height $image] if {$width * $height == 0} { error "bad image" } # create corresponding planes for {set y 0} {$y < $height} {incr y} \ { set r:row {} set g:row {} set b:row {} set t:row {} for {set x 0} {$x < $width} {incr x} \ { foreach {r g b} [$image get $x $y] break set t [$image transparency get $x $y] set t [expr {$t * 256}] foreach c {r g b t} { lappend $c:row [set $c] } } foreach c {r g b t} { lappend $c:data [set $c:row] } } # compute the new image content set Width [expr {round($width * $coef)}] set Height [expr {round($height * $coef)}] set ey 0 set y2 0 set cy2 $Height for {set Y 0} {$Y < $Height} {incr Y} \ { set r:Row {} set g:Row {} set b:Row {} set t:Row {} # y1 is the top coordinate in the old image set y1 $y2 set cy1 [expr {$Height - $cy2}] incr ey $height set y2 [expr {$ey / $Height}] set cy2 [expr {$ey % $Height}] if {$y1 == $y2} { set cy1 $cy2 } set ex 0 set x2 0 set cx2 $Width for {set X 0} {$X < $Width} {incr X} \ { set x1 $x2 set cx1 [expr {$Width - $cx2}] incr ex $width set x2 [expr {$ex / $Width}] set cx2 [expr {$ex % $Width}] if {$x1 == $x2} { set cx1 $cx2 } # compute pixel foreach c {r g b t} { set $c 0; set _$c 0 } for {set y $y1} {$y <= $y2} {incr y} \ { # compute y coef switch $y \ $y1 { set cy $cy1 } \ $y2 { set cy $cy2 } \ default { set cy $height } if {$cy == 0} { continue } if {$cy > $height} { set cy $height } for {set x $x1} {$x <= $x2} {incr x} \ { # compute x coef switch $x \ $x1 { set cx $cx1 } \ $x2 { set cx $cx2 } \ default { set cx $width } if {$cx == 0} { continue } if {$cx > $width} { set cx $width } # weight each initial pixel by cx & cy set cxy [expr {$cx * $cy / double($width) / $height}] foreach c {r g b t} \ { set comp [lindex [set $c:data] $y $x] incr $c [expr {round($comp * $cxy)}] set _$c [expr {[set _$c] + $cxy}] } } } set _ {} foreach c {r g b t} \ { set comp [set $c] if {$comp > 255} { set comp 255 } lappend $c:Row $comp lappend _ [set _$c] } } foreach c {r g b t} { lappend $c:Data [set $c:Row] } } # crisping for {set Y 0} {$Y < $Height} {incr Y} \ { set Row {} set tRow {} for {set X 0} {$X < $Width} {incr X} \ { if {$X == 0 || $X == $Width - 1 || $Y == 0 || $Y == $Height - 1} \ { foreach c {r g b} { set $c [lindex [set $c:Data] $Y $X] } } \ else \ { foreach c {r g b t} \ { set c00 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 1}]] set c01 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 0}]] set c02 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X + 1}]] set c10 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 1}]] set c11 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 0}]] set c12 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X + 1}]] set c20 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 1}]] set c21 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 0}]] set c22 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X + 1}]] set cc [expr {int(1.4 * $c11 - 0.05 * ($c00 + $c01 + $c02 + $c10 + $c12 + $c20 + $c21 + $c22))}] if {$cc < 0} { set cc 0 } if {$cc > 255} { set cc 255 } set $c $cc } } lappend Row [format #%02x%02x%02x $r $g $b] lappend tRow [expr {round($t)}] } lappend Data $Row lappend tData $tRow } # create the new image set Image [image create photo] # fill the new image $Image put $Data # set transparency for {set Y 0} {$Y < $Height} {incr Y} \ { for {set X 0} {$X < $Width} {incr X} \ { set t [lindex $tData $Y $X] set t [expr {$t > 128 ? 1 : 0}] $Image transparency set $X $Y $t } } # return the new image return $Image } proc shrink3 {Image coef {TargetImage {}}} { # check coef if {$coef > 1.0} { error "bad coef \"$coef\": should not be greater than 1.0" } # get the old image content set Width [image width $Image] set Height [image height $Image] if {$Width==0 || $Height==0} { error "bad image" } if {$TargetImage eq ""} { # create new image set image [image create photo] } else { set image $TargetImage } if {abs($coef - 1.0) < 1.e-4} { $image copy $Image return $image } set Factor [expr {double($Width)*$Height}] # Extract the data from the source - experiment indicates that this is the fastest way foreach row [$Image data] { set rdata {} foreach pixel $row { lappend rdata [scan $pixel "#%2x%2x%2x"] } lappend DATA $rdata } # compute the new image content set width [expr {round($Width * $coef)}] set height [expr {round($Height * $coef)}] set ey 0 set Y2 0 set cy2 $height for {set y 0} {$y < $height} {incr y} { # Y1 is the top coordinate in the old image set Y1 $Y2 set cy1 [expr {$height - $cy2}] incr ey $Height set Y2 [expr {$ey / $height}] set cy2 [expr {$ey % $height}] if {$Y1 == $Y2} { set cy1 $cy2 } set ex 0 set X2 0 set cx2 $width set row {} for {set x 0} {$x < $width} {incr x} { set X1 $X2 set cx1 [expr {$width - $cx2}] incr ex $Width set X2 [expr {$ex / $width}] set cx2 [expr {$ex % $width}] if {$X1 == $X2} { set cx1 $cx2 } # compute pixel set r 0.0 set g 0.0 set b 0.0 for {set Y $Y1} {$Y <= $Y2} {incr Y} { # compute y coef if {$Y == $Y1} { if {$cy1 == 0} continue set cy [expr {$cy1>$Height ? $Height : $cy1}] } elseif {$Y == $Y2} { if {$cy2 == 0} continue set cy [expr {$cy2>$Height ? $Height : $cy2}] } else { set cy $height } for {set X $X1} {$X <= $X2} {incr X} { # compute x coef if {$X == $X1} { if {$cx1 == 0} continue set cx [expr {$cx1>$Width ? $Width : $cx1}] } elseif {$X == $X2} { if {$cx2 == 0} continue set cx [expr {$cx2>$Width ? $Width : $cx2}] } else { set cx $width } # weight each initial pixel by cx & cy set cxy [expr {$cx * $cy / $Factor}] set pixel [lindex $DATA $Y $X] set r [expr {$r+([lindex $pixel 0] * $cxy)}] set g [expr {$g+([lindex $pixel 1] * $cxy)}] set b [expr {$b+([lindex $pixel 2] * $cxy)}] } } lappend row [format "#%02x%02x%02x" \ [expr {$r>255.0 ? 255 : round($r)}] \ [expr {$g>255.0 ? 255 : round($g)}] \ [expr {$b>255.0 ? 255 : round($b)}]] } lappend data $row } # fill the new image $image blank $image put $data # return the new image return $image } } package require Img namespace import ::iredexp::expand ::iredexp::expand2 ::iredexp::shrink3 set iori [image create photo -file etc/MACSIM_100px_transparent.gif] foreach i {1. 1.2 1.4 1.45} { set ix$i [::iredexp::expand2 $iori $i] } foreach i {1. 0.8 0.6 0.55} { set is$i [::iredexp::shrink3 $iori $i] } set w ".test" frame $w set j 0 foreach i {1. 1.2 1.4 1.45} { incr j label $w.lix$j -image [set ix$i] label $w.cix$j -text " $i " grid $w.lix$j -row 0 -column $j grid $w.cix$j -row 1 -column $j } set j 0 foreach i {1. 0.8 0.6 0.55} { incr j label $w.lis$j -image [set is$i] label $w.cis$j -text " $i " grid $w.lis$j -row 2 -column $j grid $w.cis$j -row 3 -column $j } pack $w