images.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) 2014 Adafruit Industries
  2. # Author: Tony DiCola
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. # This example is for use on (Linux) computers that are using CPython with
  22. # Adafruit Blinka to support CircuitPython libraries. CircuitPython does
  23. # not support PIL/pillow (python imaging library)!
  24. from board import SCL, SDA
  25. import busio
  26. from PIL import Image
  27. import adafruit_ssd1306
  28. # Create the I2C interface.
  29. i2c = busio.I2C(SCL, SDA)
  30. # Create the SSD1306 OLED class.
  31. # The first two parameters are the pixel width and pixel height. Change these
  32. # to the right size for your display!
  33. disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
  34. # Note you can change the I2C address, or add a reset pin:
  35. # disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c, reset=reset_pin)
  36. # Clear display.
  37. disp.fill(0)
  38. disp.show()
  39. # Load image based on OLED display height. Note that image is converted to 1 bit color.
  40. #if disp.height == 64:
  41. # image = Image.open("happycat_oled_64.ppm").convert("1")
  42. #else:
  43. # image = Image.open("happycat_oled_32.ppm").convert("1")
  44. # Alternatively load a different format image, resize it, and convert to 1 bit color.
  45. image = Image.open('/home/pi/OnionPi/tor.png').resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')
  46. # Display image.
  47. disp.image(image)
  48. disp.show()