|
From: Bryan Green on 25 Jun 2008 12:47 Hello, all-- I'm wondering if someone can give me a quick tutorial on loading images into widgets... I've been struggling with this for days and I'm on the verge of pulling my hair out. I've tried all the code snippets I've found, none of which has worked. I'm convinced that the "-shrink" option of the "image" command does nothing. Here's an example of code I've tried, from the "TKPhotoLab" tutorial in the tcl/tk wiki: proc loadImg {{fn ""}} { if {$fn==""} {set fn [tk_getOpenFile]} if {$fn != ""} { cd [file dirname [file join [pwd] $fn]] set ::im1 [image create photo -file $fn] .1 config -image $::im1 set ::im2 [image create photo] .2 config -image $::im2 $::im2 copy $::im1 -shrink set ::info "Loaded image 1 from $fn" } } When I use this code, my images aren't shrunk to fit the labels on which they're placed-- they just get clipped, and only the top-left corner shows up in the label. Thanks! Bryan
From: Bryan Oakley on 25 Jun 2008 13:22 Bryan Green wrote: > Hello, all-- I'm wondering if someone can give me a quick tutorial on > loading images into widgets... > > I've been struggling with this for days and I'm on the verge of pulling > my hair out. I've tried all the code snippets I've found, none of which > has worked. I'm convinced that the "-shrink" option of the "image" > command does nothing. Here's an example of code I've tried, from the > "TKPhotoLab" tutorial in the tcl/tk wiki: > > proc loadImg {{fn ""}} { > if {$fn==""} {set fn [tk_getOpenFile]} > if {$fn != ""} { > cd [file dirname [file join [pwd] $fn]] > set ::im1 [image create photo -file $fn] > .1 config -image $::im1 > set ::im2 [image create photo] > .2 config -image $::im2 > $::im2 copy $::im1 -shrink > set ::info "Loaded image 1 from $fn" > } > } > > When I use this code, my images aren't shrunk to fit the labels on which > they're placed-- they just get clipped, and only the top-left corner > shows up in the label. > > Thanks! > Bryan Images in tcl will never shrink (or grow) to fit. Tk images aren't scaleable. Typically it works the other way around, with the label growing or shrinking to fit the image. Though, this behavior depends on how the widget is configured and managed. If the labels are a fixed size, the cropping behavior is what you get. As for the effect of the -shrink option -- it doesn't do what you seem to think it does. All it will do is resize the destination image to fit what's being copied in at the time of the copy. So, if im1 is smaller than im2 (impossible in the above case since you didn't specify a size), im2 will be the same size as im1 when you copy im1 into it.
From: Bryan Green on 25 Jun 2008 13:41 > Images in tcl will never shrink (or grow) to fit. Tk images aren't > scaleable. Typically it works the other way around, with the label > growing or shrinking to fit the image. Though, this behavior depends on > how the widget is configured and managed. If the labels are a fixed > size, the cropping behavior is what you get. > > As for the effect of the -shrink option -- it doesn't do what you seem > to think it does. All it will do is resize the destination image to fit > what's being copied in at the time of the copy. So, if im1 is smaller > than im2 (impossible in the above case since you didn't specify a size), > im2 will be the same size as im1 when you copy im1 into it. Interesting...the TKPhotoLab demo (and other examples I've seen) lead one to believe that one can automatically shrink down images to fit on widgets. Thanks for clearing this up for me. I'll use ImageMagick to create temporary copies of images for display in widgets... Bryan
From: keithv on 25 Jun 2008 15:48 On Jun 25, 1:41 pm, Bryan Green <bcgr...(a)gmail.com> wrote: > > Images in tcl will never shrink (or grow) to fit. Tk images aren't > > scaleable. Typically it works the other way around, with the label > > growing or shrinking to fit the image. Though, this behavior depends on > > how the widget is configured and managed. If the labels are a fixed > > size, the cropping behavior is what you get. > > > As for the effect of the -shrink option -- it doesn't do what you seem > > to think it does. All it will do is resize the destination image to fit > > what's being copied in at the time of the copy. So, if im1 is smaller > > than im2 (impossible in the above case since you didn't specify a size), > > im2 will be the same size as im1 when you copy im1 into it. > > Interesting...the TKPhotoLab demo (and other examples I've seen) lead one > to believe that one can automatically shrink down images to fit on > widgets. Thanks for clearing this up for me. I'll use ImageMagick to > create temporary copies of images for display in widgets... If you're on Windows and only need scaling, I've found that xphoto (http://wiki.tcl.tk/11924) to be much lighter weight and simpler to use than ImageMagick. Keith
From: spam on 25 Jun 2008 15:56 On Wed, 25 Jun 2008, Bryan Green wrote: > Date: Wed, 25 Jun 2008 12:41:42 -0500 > From: Bryan Green <bcgreen(a)gmail.com> > Newsgroups: comp.lang.tcl > Subject: Re: Shrink Image to Fit Widget? > >> Images in tcl will never shrink (or grow) to fit. Tk images aren't >> scaleable. Typically it works the other way around, with the label >> growing or shrinking to fit the image. Though, this behavior depends on >> how the widget is configured and managed. If the labels are a fixed >> size, the cropping behavior is what you get. >> >> As for the effect of the -shrink option -- it doesn't do what you seem >> to think it does. All it will do is resize the destination image to fit >> what's being copied in at the time of the copy. So, if im1 is smaller >> than im2 (impossible in the above case since you didn't specify a size), >> im2 will be the same size as im1 when you copy im1 into it. > > Interesting...the TKPhotoLab demo (and other examples I've seen) lead one > to believe that one can automatically shrink down images to fit on > widgets. Thanks for clearing this up for me. I'll use ImageMagick to > create temporary copies of images for display in widgets... > > Bryan > # # img_scale not fast, but does not require tclmagick ... proc img_scale { im mx_wd mx_ht } { set w [ image width $im ] set h [ image height $im ] set iw $mx_wd set ih $mx_ht set new [ image create photo -format jpeg -width $iw -height $ih ] set smp_x [ expr $w / $iw ] set smp_y [ expr $h / $ih ] $new copy $im -subsample $smp_x $smp_y -shrink -to 0 0 $iw $ih return $new } HTH, Rob Sciuk ---- Posted via Pronews.com - Premium Corporate Usenet News Provider ---- http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
|
Next
|
Last
Pages: 1 2 Prev: Expect: Cannot send commands from a function Next: Embedding Cell in a table |