| 1 | #!/usr/bin/python
|
|---|
| 2 | '''
|
|---|
| 3 | Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | '''
|
|---|
| 18 |
|
|---|
| 19 | import sys
|
|---|
| 20 | import os
|
|---|
| 21 | import getopt
|
|---|
| 22 | from PIL import Image
|
|---|
| 23 | from PIL import ImageOps
|
|---|
| 24 | from EPD import EPD
|
|---|
| 25 |
|
|---|
| 26 | def displayImage(epd, imageFilePath):
|
|---|
| 27 | image = Image.open(imageFilePath)
|
|---|
| 28 | image = ImageOps.grayscale(image)
|
|---|
| 29 | imageResized = image.resize((epd.width, epd.height))
|
|---|
| 30 | imageBlackWhite = imageResized.convert("1", dither=Image.FLOYDSTEINBERG)
|
|---|
| 31 | epd.display(imageBlackWhite)
|
|---|
| 32 | epd.update()
|
|---|
| 33 |
|
|---|
| 34 | def usage():
|
|---|
| 35 | print "Usage of gnuboat-splashscreen:"
|
|---|
| 36 | print " gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY"
|
|---|
| 37 | print ""
|
|---|
| 38 | print " -h --help Print this help"
|
|---|
| 39 | print " -i --image Path to the image, which should be displayed"
|
|---|
| 40 | sys.exit()
|
|---|
| 41 |
|
|---|
| 42 | def main(argv):
|
|---|
| 43 | image = ""
|
|---|
| 44 | try:
|
|---|
| 45 | opts, args = getopt.getopt(argv, "hi:", ["help", "image="])
|
|---|
| 46 | except getopt.GetoptError:
|
|---|
| 47 | usage()
|
|---|
| 48 | sys.exit(2)
|
|---|
| 49 |
|
|---|
| 50 | for option, argument in opts:
|
|---|
| 51 | if option == ("-h", "--help"):
|
|---|
| 52 | usage()
|
|---|
| 53 | sys.exit()
|
|---|
| 54 | elif option in ("-i", "--image"):
|
|---|
| 55 | image = argument
|
|---|
| 56 | else:
|
|---|
| 57 | assert False, "unhandled option"
|
|---|
| 58 |
|
|---|
| 59 | if not os.path.exists(image):
|
|---|
| 60 | print "Image %s not found" % image
|
|---|
| 61 | print ""
|
|---|
| 62 | usage()
|
|---|
| 63 | sys.exit(2)
|
|---|
| 64 |
|
|---|
| 65 | epd = EPD()
|
|---|
| 66 | epd.clear()
|
|---|
| 67 | displayImage(epd, image)
|
|---|
| 68 |
|
|---|
| 69 | if __name__ == "__main__":
|
|---|
| 70 | main(sys.argv[1:])
|
|---|