#!/usr/bin/env python
# -*- coding: utf-8; mode: Python -*-
#
#
# Lars Jørgen Solberg <supersolberg@gmail.com> 2014
#
import argparse
import Image
import sys

import shellpic

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("image")
    parser.add_argument("--shell8", action="store_true", 
                        help="Print text suitable for a shell capable of displaying 8bit colors (default)")
    parser.add_argument("--shell24", action="store_true", 
                        help="Print text suitable for a shell capable of displaying 24bit colors")
    parser.add_argument("--irc", action="store_true", 
                        help="Print text suitable for piping to an irc client")
    args = parser.parse_args()

    if args.irc:
        formatter = shellpic.Irc()
    elif args.shell24:
        formatter = shellpic.Shell24Bit()
    else:
        formatter = shellpic.Shell8bit()

    img = Image.open(args.image)
    img = shellpic.scale(img, *formatter.dimentions())
    
    text = formatter.format(img)
    print text.encode('utf-8')
