Automatic output name

No longer needs an output file to be specified - uses whatever the input file was called, changes extension to .img
This commit is contained in:
James 2021-02-07 10:15:13 +11:00 committed by GitHub
parent d51352ed64
commit 4559a5ff03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -2,12 +2,16 @@
import math
import sys
from PIL import Image
import os
image = Image.open(sys.argv[1]).convert('L')
inputFilename = sys.argv[1]
outputFilename = os.path.splitext(inputFilename)[0] + ".img"
image = Image.open(inputFilename).convert('L')
bitsPerRow = math.ceil(image.width/8) * 8
paddingBits = bitsPerRow - image.width
outputFile = open(sys.argv[2], "wb")
outputFile = open(outputFilename, "wb")
outputFile.write(bytes((image.width,)))
outputFile.write(bytes((image.height,)))
@ -30,4 +34,4 @@ for row in range(image.height):
outputByte += "0"
outputFile.write(bytes((int(outputByte,2),)))
outputFile.close()
outputFile.close()