GIMP Chat
http://gimpchat.com/

Zoom
http://gimpchat.com/viewtopic.php?f=9&t=19516
Page 1 of 1

Author:  Sweeney [ Wed Jul 28, 2021 2:23 pm ]
Post subject:  Zoom

Hi all,

anybody know a script-fu way to set the zoom of an image to 100% ?

Thanks

Author:  PixLab [ Wed Jul 28, 2021 8:46 pm ]
Post subject:  Re: Zoom

Is it to write a script?

If not -> Just hit the 1 key on your keyboard = 100%
2 = 200%
3 = 400%
and so

Ctrl +Shift + J = fit canvas

Author:  ofnuts [ Thu Jul 29, 2021 1:52 am ]
Post subject:  Re: Zoom

Sweeney wrote:
Hi all,

anybody know a script-fu way to set the zoom of an image to 100% ?

Thanks


There is none, by design, scripts cannot interact with the UI. But the shortcut to "View->100%" is "1".

Author:  AlSchemist [ Fri Nov 05, 2021 3:26 pm ]
Post subject:  Driving Gimp's GUI with PowerShell

Hello Sweeney,

1. Run :bowdown PowerShell

Click Windows "Start" > Windows "PowerShell" or "Windows PowerShell ISE"

Before running any PowerShell script, give the following permission one time per session:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

Copy in the clipboard the above PowerShell command by Ctrl+C.
Then paste it by Ctrl+V in the PowerShell console or the Windows ISE running console.
Don't forget to validate this command by pressing the "ENTER" key in the console.

Dlgbox "Execution Policy Change":
Windows PowerShell wrote:
The execution policy helps protect you from scripts that you do not trust.
Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170.
Do you want to change the execution policy?

Click Yes
The change of policy is enabled only during the current session.
If you close Windows ISE or the PowerShell console, the protective policy is again applied.
Remember that the (pre-)historic :shoot MS/DOS :pound console did not have this kind of policy.


2. Run Gimp

Click Windows "Start" > Gimp 2.10.28
Reorganize the Gimp window and the PowerShell ISE or PowerShell console side-by-side in order to see the result of the PowerShell command on Gimp.
Do not overlap the PowerShell console window above the Gimp window.

Gimp menu "File" > "Open" your preferred image you wish to zoom.

Be sure that the zoom is at for example 200%:
Gimp menu "View" > "Zoom" > 2:1 (200%)
or press the shortcut "2" just after the loading of your picture.


3. Define GimpZoom

Copy by Ctrl+C the following PowerShell script defining the function GimpZoom:
function GimpZoom
{
    param   (
        [parameter(Position=0)][int]$level = 100
            )
    process
    {
        $wsh = New-Object -ComObject WScript.Shell
        $wsh.AppActivate((Get-Process gimp-2.10).Id)   
        start-sleep -Milliseconds 500
        switch ($level)
        {
           1600     {$key = "5" ; Break} # 1600%
            800     {$key = "4" ; Break} #  800%
            400     {$key = "3" ; Break} #  400%
            200     {$key = "2" ; Break} #  200%
             50     {$key = "6" ; Break} #   50%
            default {$key = "1" ; Break} #  100%
        }
        if ($key.Length -gt 0) {$wsh.SendKeys($key)}
        Write-Host "key = $key"
    }
}

The script retrieves the ID of the Gimp 2.10 process.
Then it sends the wished shortcut according to the level parameter.
The COM application is named Windows Script Host (WSH) available in each standard Windows.

Paste by Ctrl+V the content of the clipboard in the PowerShell ISE editor or the PowerShell console:
In the PowerShell IDE, click Run (F5) to define the function GimpZoom.
In the PowerShell console, after the paste, the function GimpZoom is defined.


4. Call GimpZoom

Copy and paste the call of the function with as level parameter the integer 100 meaning 100%: :keybdtype
GimpZoom -level 100

Do not enter the "%" symbol. :nono

When you validate the call of the function by "ENTER"
the GIMP zoom is set to 100% as required. :geek:

Note: if you wish to reduce the zoom to 50%, the default shortcut "Shift+2" :roll: is too difficult to simulate.
Normally Shift is coded by "+" but on QWERTY keyboard even if the key "2" is directly available,
Shift+2 would generate another character that Gimp does not understand.

That is why it is suggested to replace the Shift+N shortcuts with direct simpler integers such as 6 to 8.
0 and 9 are already used.
That is why for the -level 50, the shortcut 6 is simulated.


5. Define and call GimpZoomLoop :hexer

Finally, optionally copy and paste GimpZoomLoop.
function GimpZoomLoop()
{
    for ($level = 100; $level -le 1600; $level *= 2)
    {
        GimpZoom -level $level
        start-sleep -Seconds 1
    }
    for ($level = 1600; $level -ge 100; $level /= 2)
    {
        GimpZoom -level $level
        start-sleep -Seconds 1
    }
}

This function calls GimpZoom with level from 100% to 1600% then from 1600% to 100% :wh
sleeping 1 second between two calls.


6. Conclusion about automation testing via the GUI

The PowerShell script GimpZoom does not know when the operation of change of the Gimp zoom is really over.
We need to sleep :zzz during a tempo that you could need to adapt according to the power of your PC.

Driving the Gimp's GUI is strongly dependent on:
  • the Operating System, Windows;
  • the Gimp's shortcut and language;
  • the language of the keyboard;
  • the power of the PC about each tempo.

Synchronizing automatically the PowerShell script with Gimp :hugme is out of the scope of this article. :bawl
For example, reading that the GUI changed
in order to be sure that the current operation is over :rofl
before sending another keystroke. :lmao

For more information, search free tools for automation testing.

Author:  Tas_mania [ Fri Nov 05, 2021 5:58 pm ]
Post subject:  Re: Zoom

You're out of luck. Can't use Gimp to do zooms.


Image

Author:  AlSchemist [ Sat Nov 06, 2021 6:06 am ]
Post subject:  Infinite Zoom

Tas_mania, I cannot compete with your Infinite Zoom! :jumpclap

Author:  lylejk [ Sun Nov 07, 2021 10:52 pm ]
Post subject:  Re: Zoom

That is a cool effect, Tas. :)

Author:  Tas_mania [ Sun Nov 07, 2021 11:43 pm ]
Post subject:  Re: Zoom

eh, eh the zoom only has 6 frames. Done with G'MIC zoom and a batch script I made for the command line version of G'MIC.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/