Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Limits resize enhancement #529

Closed
plum7x opened this issue Oct 30, 2023 · 10 comments
Closed

[Feature Request] Limits resize enhancement #529

plum7x opened this issue Oct 30, 2023 · 10 comments
Labels
easy enhancement New feature or request

Comments

@plum7x
Copy link
Contributor

plum7x commented Oct 30, 2023

An option to rotate the limit box depending on original image orientation.

For example the both side lengths of the limit box are 3840 and 2560 then

resize below 3840x2560 for the landscape images
4000x3000 -> 3414x2560
4000x2250 -> 3840x2160
1920x1440 -> 1920x1440
1920x1080 -> 1920x1080
...

and resize below 2560x3840 for the portrait images
3000x4000 -> 2560x3414
2250x4000 -> 2160x3840
1440x1920 -> 1440x1920
1080x1920 -> 1080x1920
...

@T8RIN
Copy link
Owner

T8RIN commented Oct 30, 2023

Didn't get it, is it not work the same now?

@T8RIN T8RIN added the enhancement New feature or request label Oct 30, 2023
@plum7x
Copy link
Contributor Author

plum7x commented Oct 30, 2023

The orientation of the limit box is fixed, but I hope it will can rotate automatically. Then I don't have to resize separately for the pictures in different directions.

@T8RIN
Copy link
Owner

T8RIN commented Oct 30, 2023

Hm, can you explain it using abstract numbers and inequalities please?👀

@plum7x
Copy link
Contributor Author

plum7x commented Oct 30, 2023

the following powershell script did what I wanted.

[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$image = [System.Drawing.Image]::FromFile($imageFilePath)

$imageAspectRatio = $image.Width / $image.Height

$_limitWidth  = $limitWidth
$_limitHeight = $limitHeight
if ($imageAspectRatio -ge 1.0)
{    
    # Set limit box as landscape 
    $limitWidth     = ($_limitWidth, $_limitHeight | Measure-Object  -Maximum).Maximum
    $limitHeight    = ($_limitWidth, $_limitHeight | Measure-Object  -Minimum).Minimum    
}
else
{
    # Set limit box as portrait
    $limitWidth     = ($_limitWidth, $_limitHeight | Measure-Object  -Minimum).Minimum
    $limitHeight    = ($_limitWidth, $_limitHeight | Measure-Object  -Maximum).Maximum
}

$limitBoxAspectRatio = $limitWidth / $limitHeight

$isOverTheLimit = ($image.Width -gt $limitWidth) -or ($image.Height -gt $limitHeight)

if ($isOverTheLimit)
{
     # Limits resize
    if ($imageAspectRatio -ge $limitBoxAspectRatio)
    {
        # Resize by width and keep the ratio
        $scaleWidth     = $limitWidth
        $scaleHeight    = ($limitWidth / $imageAspectRatio) -as [int]
    }
    else
    {
        # Resize by Height and keep the ratio
        $scaleWidth     = ($limitHeight * $imageAspectRatio) -as [int]
        $scaleHeight    = $limitHeight
    }
}
else
{
    # Keep original size
    $scaleWidth  = $image.Width
    $scaleHeight = $image.Height
}

@T8RIN
Copy link
Owner

T8RIN commented Oct 30, 2023

thanks 👀

@plum7x
Copy link
Contributor Author

plum7x commented Oct 31, 2023

Another problem, no save button in the latest version.

@T8RIN
Copy link
Owner

T8RIN commented Oct 31, 2023

Another problem, no save button in the latest version.

Where?

@plum7x
Copy link
Contributor Author

plum7x commented Oct 31, 2023

limits resize
ResizedImage_2023-10-31_19-10-41_1330.png

@T8RIN
Copy link
Owner

T8RIN commented Oct 31, 2023

You need to select preset or limit box to appear

@plum7x
Copy link
Contributor Author

plum7x commented Oct 31, 2023

i see, thanks. both width and height must be set. i originally thought that it will use the maximum value depending on the image format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants