janalysis/__main__.py
def main():
    """Gets the options for converting a PNG to a JPEG."""
    inputfile = None
    outputfile = None
    scalefactor = None
    use_fct = 'y'
    if len(sys.argv) > 1:
        # Command line options used
        inputfile = sys.argv[1]
        outputfile = sys.argv[2]
        scalefactor = float(sys.argv[3])
    else:
        # Prompt for settings
        inputfile = input('Enter PNG file to convert to a jpeg: ')
        outputfile = input('Enter desired name of output file: ')
        print('Original quantization matrix:')
        print(L_QUANTIZATION_TABLE)
        scalefactor = float(input('Enter scaling factor for quantization matrix: '))
        use_fct = input('Use FCT instead of regular DCT? (y/n): ')
    start_time = time.time()
    if use_fct == 'y':
        jpeg_encode(inputfile, scalefactor, outputfile)
    else:
        jpeg_encode(inputfile, scalefactor, outputfile, False)
    end_time = time.time()
    print('Time taken to convert image: {:.2f}'.format(end_time - start_time))
    original_size = os.path.getsize(inputfile)
    new_size = os.path.getsize(outputfile)
    print('PNG file size: {} bytes'.format(original_size))
    print('JPEG file size: {} bytes'.format(new_size))
    percent_smaller = 100*float(original_size-new_size)/original_size
    print('JPEG file size is {:.2f}% smaller than the PNG file size'.format(percent_smaller))
    sys.exit(0)
Gets the options for converting a PNG to a JPEG.
Gets the options for converting a PNG to a JPEG.
Gets the options for converting a PNG to a JPEG .
def main():
    inputfile = None
    outputfile = None
    scalefactor = None
    use_fct = 'y'
    if len(sys.argv) > 1:
        inputfile = sys.argv[1]
        outputfile = sys.argv[2]
        scalefactor = float(sys.argv[3])
    else:
        inputfile = input('Enter PNG file to convert to a jpeg: ')
        outputfile = input('Enter desired name of output file: ')
        print('Original quantization matrix:')
        print(L_QUANTIZATION_TABLE)
        scalefactor = float(input('Enter scaling factor for quantization matrix: '))
        use_fct = input('Use FCT instead of regular DCT? (y/n): ')
    start_time = time.time()
    if use_fct == 'y':
        jpeg_encode(inputfile, scalefactor, outputfile)
    else:
        jpeg_encode(inputfile, scalefactor, outputfile, False)
    end_time = time.time()
    print('Time taken to convert image: {:.2f}'.format(end_time - start_time))
    original_size = os.path.getsize(inputfile)
    new_size = os.path.getsize(outputfile)
    print('PNG file size: {} bytes'.format(original_size))
    print('JPEG file size: {} bytes'.format(new_size))
    percent_smaller = 100*float(original_size-new_size)/original_size
    print('JPEG file size is {:.2f}% smaller than the PNG file size'.format(percent_smaller))
    sys.exit(0)
def main ( ) : inputfile = None outputfile = None scalefactor = None use_fct = 'y' if len ( sys . argv ) > 1 : inputfile = sys . argv [ 1 ] outputfile = sys . argv [ 2 ] scalefactor = float ( sys . argv [ 3 ] ) else : inputfile = input ( 'Enter PNG file to convert to a jpeg: ' ) outputfile = input ( 'Enter desired name of output file: ' ) print ( 'Original quantization matrix:' ) print ( L_QUANTIZATION_TABLE ) scalefactor = float ( input ( 'Enter scaling factor for quantization matrix: ' ) ) use_fct = input ( 'Use FCT instead of regular DCT? (y/n): ' ) start_time = time . time ( ) if use_fct == 'y' : jpeg_encode ( inputfile , scalefactor , outputfile ) else : jpeg_encode ( inputfile , scalefactor , outputfile , False ) end_time = time . time ( ) print ( 'Time taken to convert image: {:.2f}' . format ( end_time - start_time ) ) original_size = os . path . getsize ( inputfile ) new_size = os . path . getsize ( outputfile ) print ( 'PNG file size: {} bytes' . format ( original_size ) ) print ( 'JPEG file size: {} bytes' . format ( new_size ) ) percent_smaller = 100 * float ( original_size - new_size ) / original_size print ( 'JPEG file size is {:.2f}% smaller than the PNG file size' . format ( percent_smaller ) ) sys . exit ( 0 )
Gets the options for converting a PNG to a JPEG.
Gets the options for converting a PNG to a JPEG .
"""Gets the options for converting a PNG to a JPEG.""" # Command line options used # Prompt for settings