I'm trying to scale an image from a jpeg file to fit a window. Curretly I'm running the output of the ImageMagick convert command through a temporary file to Tk image create:
# use a temporary file
close [file tempfile tf]
puts "Configure: [winfo height $win] [winfo width $win]"
try {
# resize photo to fit window, preserve aspect ratio
exec convert [file normalize $file] -resize [winfo width $win]x[winfo height $win] jpeg:$tf
set image [image create photo -format jpeg -file $tf]
$win.img configure -image $image
} finally {file delete $tf}
I made an attempt to send convert's output to stdout (using jpeg:-) and use the output of the [exec] directly in the image create photo command as -data. However I get format not recognized errors.
Is there a better way to fit a jpeg in a window whose size can change?
Have a look at this extension:
https://github.com/auriocus/PhotoResize/
In particular, the demo/ folder contains a script with a widget that
scales an image to fit the window and allows resizing, zooming in/out
and dragging around the image.
Binaries of the extension compiled via Github Actions are also
available: https://github.com/auriocus/PhotoResize/releases (under Assets)
Christian
were errors. The frst error was:Have a look at this extension:
https://github.com/auriocus/PhotoResize/
In particular, the demo/ folder contains a script with a widget that
scales an image to fit the window and allows resizing, zooming in/out
and dragging around the image.
Binaries of the extension compiled via Github Actions are also
available: https://github.com/auriocus/PhotoResize/releases (under Assets) >>
Christian
This looks like what I'm trying to do. However once I figured out how to get a tarball from GitHub, I got errors when trying to compile. ./configure worked, there was a warning about needing SWIG 1.3... and I have version 3... however after make there
./generic/photoresize.cpp:273:18: error: template argument 1 is invalid
class accum<tuple> {
^
./generic/photoresize.cpp: In function ‘std::__cxx11::string resizephoto(Tcl_Interp*, Tk_PhotoHandle, Tk_PhotoHandle, int, int)’:
./generic/photoresize.cpp:330:17: error: template argument 1 is invalid
vector <tuple> pixelPtr(xsize*ysize);
^
I'm not sure what is going wrong, my appreciation of C++ stopped with: it's C with classes and // comments. I'm not used to SWIG either (I stick my Tcl_CreateObjCommand(...) in a Whatever_Init function). Perhaps it's the rather ancient Slackware 14.2Linux distribution I'm compiling on. A new version of Slackware is imminent, so I will try again when that is available.
Dave B
Am 24.01.22 um 17:58 schrieb clt.to.davebr@dfgh.net:
Have a look at this extension:
https://github.com/auriocus/PhotoResize/
In particular, the demo/ folder contains a script with a widget that
scales an image to fit the window and allows resizing, zooming in/out
and dragging around the image.
Binaries of the extension compiled via Github Actions are also
available: https://github.com/auriocus/PhotoResize/releases (under
Assets)
Christian
This looks like what I'm trying to do. However once I figured out how
to get a tarball from GitHub, I got errors when trying to compile.
./configure worked, there was a warning about needing SWIG 1.3... and
I have version 3... however after make there were errors. The frst
error was:
./generic/photoresize.cpp:273:18: error: template argument 1 is invalid
class accum<tuple> {
^
./generic/photoresize.cpp: In function ‘std::__cxx11::string
resizephoto(Tcl_Interp*, Tk_PhotoHandle, Tk_PhotoHandle, int, int)’:
./generic/photoresize.cpp:330:17: error: template argument 1 is invalid
vector <tuple> pixelPtr(xsize*ysize);
^
I'm not sure what is going wrong,
I used the link to the .zip file. It compiled, loaded into Tk, and worked as advertised with no problems.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 495 |
Nodes: | 16 (2 / 14) |
Uptime: | 41:23:43 |
Calls: | 9,743 |
Calls today: | 3 |
Files: | 13,742 |
Messages: | 6,183,796 |