[Please don't top-quote - it breaks the temporal ordering of the
context of the reply]
Mark Tarver <
dr.mt...@gmail.com> wrote:
> On Tuesday, October 31, 2017 at 2:09:33 PM UTC, Gerald Lester wrote:
>> On 10/31/2017 09:06 AM, Mark Tarver wrote:
>> > On Tuesday, October 31, 2017 at 1:40:20 PM UTC, Gerald Lester wrote:
>> >> On 10/31/2017 08:18 AM, Mark Tarver wrote:
>> >>> I want to place an image on a button but want the image resized
>> >>> to fit the dimensions of the button.
>> >>>
>> >>> I've tried resizing the image when created and resizing the
>> >>> button to no avail. If I wanted an image sized to fit a button
>> >>> of say 200 height x 100 width in pixels, how would I do it?
>> >>
>> >> I'd suggest rather you should use the -image option of the button
>> >> to say that the image should be placed in the button.
>> >>
>> > I'm configuring the height and width of the button. But the image
>> > - which is large - is simply cropped when displayed. I want to
>> > shrink it to the dimensions of the button.
>> >
>>
>> You need to resize your image to say 195 by 95 and used the resized
>> image as the -image argument to the button. Do not give the button
>> sizing information and it will form to the image.
>
> I've tried the following
>
> package require Img
> image create photo s2 -file "C:/Users/User/Desktop/Whist/PNG-cards-1.3/2_of_spades.png" -height 150 -width 90
> button .b -image s2
> pack .b
>
> package require Img
> image create photo s2 -file "C:/Users/User/Desktop/Whist/PNG-cards-1.3/2_of_spades.png"
> button .b -image s2 -height 150 -width 90
> pack .b
>
> package require Img
> image create photo s2 -file "C:/Users/User/Desktop/Whist/PNG-cards-1.3/2_of_spades.png" -height 150 -width 90
> button .b -image s2 -height 150 -width 90
> pack .b
>
> None work.
That is because the -height and -width options to the Tk image object
are not "resize to this" options. They merely set initial sizes (or
crop, as the case may be). The Tk image subsystem does not contain a
scaling module, per se. It presumes you've already prescaled your
images to the sizes you need ahead of time.
With that said, you can scale an image via proper usage of the -zoom
and -subsample options to the "copy" subcommand. But if doing this
with large images you can run into memory consumption issues.
See
http://wiki.tcl-lang.org/8448 for details on using these options to
scale an image.
Alternately, you can compile a module that actually provides a scaling
API:
http://wiki.tcl-lang.org/25685
http://wiki.tcl-lang.org/47656
http://wiki.tcl-lang.org/5581