Any comments?
The best description of the shrink option I could find is the following:
-shrink
Shrinks the destination so that its bottom-right corner
matches the bottom-right corner of the data copied in.
This has no effect if the width and height have been
set for the image
—Practical Programming in Tcl and Tk
I think that means the shrink option just sizes the destination image to
the size of the rectangle being copied.
However, according to the ruby TkPhotoImage.new() docs:
==
If you don’t specify a width and height for an image, the image will
expand or shrink to fit the size of the data stored in the image.
So on the one hand the tcl/tk information says copy()'s shrink option
has not effect if you specify a width and height for the image(and I’ve
tested that and it’s true); but on the other hand the ruby docs say that
if you don’t specify a width and height for an image, the image will
automatically shrink or expand to the size of the data stored in it(and
I’ve tested that and it’s true) and the tcl/tk docs also so that, which
seemingly makes the shrink option superfluous.
In any case, you want the subsample option:
require ‘tk’
require ‘tkextlib/tkimg’ #*******FOR IMAGES
root = TkRoot.new
root.title = “MyWindow”
root[‘geometry’] = ‘800x500-30+50’
img = TkPhotoImage.new(
:file => ‘/Users/7stud/Desktop/photography/broken.jpg’,
)
new_img = TkPhotoImage.new(
)
puts new_img.width
puts new_img.height
new_img.copy(
img,
:from => [0, 100, 300, 300],
:subsample => [3, 3],
#:shrink => true,
)
puts new_img.width
puts new_img.height
label = TkLabel.new(root)
label.image = new_img
label.place(
‘height’ => new_img.height,
‘width’ => new_img.width,
‘x’ => 10,
‘y’ => 10
)
Tk.mainloop
–output:–
0
0
100
67