Created
January 1, 2024 13:21
-
-
Save itsuki-hayashi/2d16840e599b0e43ac7f35beffb9641c to your computer and use it in GitHub Desktop.
PowerShell 2 panel manga cutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the list of all .jpg files | |
$files = Get-ChildItem -LiteralPath . -Filter *.jpg | |
# Counter for the output file names | |
$counter = 1 | |
foreach ($file in $files) { | |
# Determine the dimensions of the image | |
$imageInfo = magick identify -format "%wx%h" $file.FullName | |
$dimensions = $imageInfo -split 'x' | |
$width = [int]$dimensions[0] | |
$height = [int]$dimensions[1] | |
# Calculate the width of each half | |
$halfWidth = [math]::Floor($width / 2) | |
# Crop the right half of the image | |
# Calculate the X-offset for the right half | |
$rightHalfFileName = "cutted-$("{0:D3}" -f $counter).jpg" | |
$counter++ | |
$xOffset = $width - $halfWidth | |
magick convert $file.FullName -crop "${halfWidth}x$height+$xOffset+0" $rightHalfFileName | |
# Crop the left half of the image | |
$leftHalfFileName = "cutted-$("{0:D3}" -f $counter).jpg" | |
$counter++ | |
magick convert $file.FullName -crop "${halfWidth}x$height+0+0" $leftHalfFileName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment