Skip to content

Instantly share code, notes, and snippets.

@ZhugeSong
Created January 25, 2020 03:49
Show Gist options
  • Save ZhugeSong/7c9ca7c4e55bde63ac85b42e4c4b1cc2 to your computer and use it in GitHub Desktop.
Save ZhugeSong/7c9ca7c4e55bde63ac85b42e4c4b1cc2 to your computer and use it in GitHub Desktop.
Convert NScripter "bw2a" format JPGs to PNGs with ImageMagick
# Converts all JPG files in the current directory from the "bw2a" format
# (the color on the left half of the image, and a mask for transparency
# on the right half) used by NScripter to PNG format with transparency.
gci . -Filter "*.jpg" |
Foreach-Object {
# Split JPG into two halves:
# - _temp-0.png is the color half
# - _temp-1.png is the mask half
magick $_ -crop 50%x100% _temp.png
# Invert the mask half (since the format uses black for opaque but
# imagemagick expects white)
magick _temp-1.png -channel RGB -negate _temp-1-i.png
# Grab the extensionless filename of the original JPG
$arg_nameonly = (gi $_).Basename
# Use the mask half to apply transparency to the color half
magick composite -compose CopyOpacity _temp-1-i.png _temp-0.png "$arg_nameonly.png"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment