Skip to content

Instantly share code, notes, and snippets.

@itsuki-hayashi
Created January 1, 2024 13:21
Show Gist options
  • Save itsuki-hayashi/2d16840e599b0e43ac7f35beffb9641c to your computer and use it in GitHub Desktop.
Save itsuki-hayashi/2d16840e599b0e43ac7f35beffb9641c to your computer and use it in GitHub Desktop.
PowerShell 2 panel manga cutter
# 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