Keith Vetter 2006-03-01 : Here's a nice visual effect that you can use when displaying photographs. It displays an image with a nice looking shadow border giving a raised, 3-d look.
The demo shows the earth rise photo from the tcl distribution with and without the shadow affect.
PWQ 8 Mar 06, Whats with the \# ? (a rhetorical question). - RS: To Tcl, \# is # (if not first character of a place where a command is expected), so the backslashes are redundant. However, some editors get confused with # not indicating a comment, so maybe that's why the backslashes were added. KPV: yes, in my case for emacs.
KPV : In Photo Gallery you can find a modification of this code which creates a single image composed of the eight border images and the main image rather than a frame with nine label widgets.
##+########################################################################## # # Shadow Photo -- displays an image with shadow border # by Keith Vetter, March 2006 # package require Tk proc ShadowPhoto {w img} { MakeBorders set width [image width $img] set height [image height $img] # Create top, left, bottom, right images of the correct size # then tile in the shadow images image create photo ::img::border::t$w -width $width -height 25 ::img::border::t$w copy ::img::border::T -to 0 0 $width 25 image create photo ::img::border::b$w -width $width -height 25 ::img::border::b$w copy ::img::border::B -to 0 0 $width 25 image create photo ::img::border::l$w -width 25 -height $height ::img::border::l$w copy ::img::border::L -to 0 0 25 $height image create photo ::img::border::r$w -width 25 -height $height ::img::border::r$w copy ::img::border::R -to 0 0 25 $height # Create the frame and 9 image labels frame $w -bg red label $w.tl -image ::img::border::TL -bd 0 label $w.t -image ::img::border::t$w -bd 0 label $w.tr -image ::img::border::TR -bd 0 label $w.l -image ::img::border::l$w -bd 0 label $w.c -image $img -bd 0 label $w.r -image ::img::border::r$w -bd 0 label $w.bl -image ::img::border::BL -bd 0 label $w.b -image ::img::border::b$w -bd 0 label $w.br -image ::img::border::BR -bd 0 grid $w.tl $w.t $w.tr -sticky news grid $w.l $w.c $w.r -sticky news grid $w.bl $w.b $w.br -sticky news return $w } ##+########################################################################## # # MakeBorders -- makes 8 images which forming the shadow gradient for the # four sides and four corners. # proc MakeBorders {} { if {[info commands ::img::border::T] ne ""} return set gradient {\#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#8d8d8d \#999999 \#a6a6a6 \#b2b2b2 \#bebebe \#c8c8c8 \#d0d0d0 \#dadada \#e2e2e2 \#e8e8e8 \#eeeeee \#f2f2f2 \#f7f7f7 \#fcfcfc \#fdfdfd \#fdfdfd \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff \#ffffff} image create photo ::img::border::T -width 1 -height 25 image create photo ::img::border::B -width 1 -height 25 image create photo ::img::border::L -width 25 -height 1 image create photo ::img::border::R -width 25 -height 1 image create photo ::img::border::TR -width 25 -height 25 image create photo ::img::border::TL -width 25 -height 25 image create photo ::img::border::BR -width 25 -height 25 image create photo ::img::border::BL -width 25 -height 25 for {set x 0} {$x < 25} {incr x} { ::img::border::B put [lindex $gradient $x] -to 0 $x ::img::border::R put [lindex $gradient $x] -to $x 0 for {set y 0} {$y < 25} {incr y} { set idx [expr {$x<5&& $y<5 ? 0 : round(hypot($x,$y))}] ::img::border::BR put [lindex $gradient $idx] -to $x $y } } ::img::border::TL copy ::img::border::BR -subsample -1 -1 ::img::border::TR copy ::img::border::BR -subsample 1 -1 ::img::border::BL copy ::img::border::BR -subsample -1 1 ::img::border::L copy ::img::border::R -subsample -1 1 ::img::border::T copy ::img::border::B -subsample 1 -1 }
################################################################# # # Demo code below # set idata { R0lGODdhQAHIAKcAAAAAAJJJJLaSSf///7ZtSdu2bdu2km0kAP/bkv//29uSbbaSbf/btkkAANv/ ////tpJtJJK229vb/7bb2yQAAJJtSUltkiRtktvbkrZtJP+2kra2bUkkAAAAJG0AANuSSQAkSba2 221JJP+2bW1JAJJJSZIkJNvbttvb221tkrbb/7ZJJJIkAAAkAP//kpJJAG0kJLZJSf/b25Lb27a2 SZKSSdu2SZKS27Ztbf+SbbaS27a2ktttbQAkJG2SkraSJNv/222StpKSbZK2tra2/7b//9uSkgAA bQAkbW3b25KStgBJSSRJbUmSkkmStm2S25KSkrYkSbaStra2ttu229u2//+SJP+SSf/bbSS2bUlJ kkmS221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owAZ YFenTvP3fSugzkwgM+NBE1qYNU4KYNZjWYT8cSVBN+dN1ElkItWrzM+PmPWEctr6vkUd8leRslVl R9WG+OCs1CH73iGtHUYTGQAwAAFvDwNby4Q3/0YEYAIkYzMmAsKv2CgvuTHVp9Ajch9rZTBxtVQS U3IZsDDTK3zNpCLKpLl5hYtSuSn2wVazxPcTUwKFezC2MtcFwANZKQA8wHKibx8VAORDfPo1wgND zPJz20aShfQ8eW4vY26VcuMqKYyAx8zsRroabur3occT/Cx46R+DwAdosEDy4iiJwVBDlJgiqzkw MYh2fO+K/F5yMvjgtB1F98InM6gfiUVylhLGAB1Gny4zMmKSiKVvb4RYnvjvMjlynSgpo67hXg1X Jdl9TfJGdxggAMHAgIECBQgQqEBAgICDBBYsUECgwMIFBSoqUACRQMQAASB8XAGh48EKJTNAYCjA 48iICxUsPAhz4kuGC7oIyBCRwIoMAgwKgLhAQAWGGSf+VOhTgIKCFSVCrKGyYwATEDYetNoQYcIf HUtUWPmxAkqURBcKCAgAOw== } . config -bg white image create photo ::img::img -data $idata ShadowPhoto .fp ::img::img label .l -image ::img::img -bd 0 pack .fp .l -side top -pady 10 -padx 10 return