• scaling images

    From clt.to.davebr@dfgh.net@21:1/5 to All on Sun Jan 23 16:38:35 2022
    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?

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Sun Jan 23 18:54:00 2022
    Am 23.01.22 um 17:38 schrieb clt.to.davebr@dfgh.net:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Mon Jan 24 16:58:48 2022
    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, 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.2
    Linux distribution I'm compiling on. A new version of Slackware is imminent, so I will try again when that is available.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Obermeier@21:1/5 to All on Mon Jan 24 20:19:12 2022
    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, 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.2
    Linux distribution I'm compiling on. A new version of Slackware is imminent, so I will try again when that is available.

    Dave B



    You might want to try the BAWT (Build Automation With Tcl) framework: www.bawt.tcl3d.org.
    It contains packages photoresize and imgtools. Both allow scaling images with arbitrary scale factors.

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Mon Jan 24 21:51:33 2022
    Am 24.01.22 um 20:19 schrieb Paul Obermeier:
    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,


    Are you sure you used the latest sources? This sounds like an error that
    was fixed a while ago; in short, "tuple" is a name in the C++ standard
    library. In the current version, line 330 reads:

    std::vector <tuple> pixelPtr(xsize*ysize);

    https://github.com/auriocus/PhotoResize/blob/6752d0e4f3694d9afa4d878b3e9aaacff7d4a21a/generic/photoresize.cpp#L330



    Also, the support for subimages and the image display widget were added
    in the recent "development" version only.

    To get code from the master branch without using git, you go to the
    green "Code" button and choose "Download ZIP"

    which points to this link: https://github.com/auriocus/PhotoResize/archive/refs/heads/master.zip

    You could also try to use the binaries compiled in the Github actions,
    they might not work, though, if your system gcc is too old.


    Best regards,

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Tue Jan 25 03:34:22 2022
    I used the link to the .zip file. It compiled, loaded into Tk, and worked as advertised with no problems.

    Thanks for the help with GitHub too. Local fossil repositories are enough for what I do.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Tue Jan 25 10:05:02 2022
    Am 25.01.22 um 04:34 schrieb clt.to.davebr@dfgh.net:
    I used the link to the .zip file. It compiled, loaded into Tk, and worked as advertised with no problems.


    You are welcome. Have you tried the demo image viewer, too? Mousewheel
    is for zooming, left button for dragging.


    BTW, your reply is not a follow-up to the original thread, and you also
    do not quote what you reply to. This iwll make it difficult for the
    future reader of this topic to understand, what is going on.

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)