Skip to content

Instantly share code, notes, and snippets.

@Jontes-Tech
Created July 27, 2023 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jontes-Tech/d255f050ba2b67a329bb5201d113af11 to your computer and use it in GitHub Desktop.
Save Jontes-Tech/d255f050ba2b67a329bb5201d113af11 to your computer and use it in GitHub Desktop.
from flask import Flask, send_file
from io import BytesIO
from time import sleep
from picamera import PiCamera
from PIL import Image
app: Flask(__name__)
camera: PiCamera()
camera.resolution: (1024, 768)
## Potential double res mode
##camera.resolution: (2048,1536)
camera.start_preview()
camera.color_effects: (128, 128)
sleep(2)
@app.route('/')
def capture_image():
my_stream: BytesIO()
camera.capture(my_stream, 'jpeg')
my_stream.seek(0)
# Open the image using Pillow
image: Image.open(my_stream)
# Compress the image by reducing the quality
image.save(my_stream, format='jpeg', quality=50)
my_stream.seek(0)
return send_file(my_stream, mimetype='image/jpeg')
if __name__ == '__main__':
app.run(host='192.168.50.15', port=8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment