Page 1 of 1

Display an image in Apache 2

Posted: Fri Sep 26, 2014 2:31 pm
by Tom T
Hello,

I have a probleme to display an image captured from picamera to a Apache 2 page :

In an index page (index.py) I can display a JPG image from a file.
But as soon as I want to display a JPG image from a capture with picamera, I have an error :
[error] [client 192.168.1.71] malformed header from script. Bad header=* failed to open vchiq instanc: index.py (from error.log file)

If someone has an idea of the error(s) made, thank you for your help.

Here is the index file:

Code: Select all

#!/usr/bin/env python

import cgi
import cgitb
cgitb.enable()
import sys
import time
import io
import aide2

a=aide2.lecture()

sys.stdout.write("Content-type: image/jpeg\n\n")
sys.stdout.write(a)
Here is the function to read a JPG file:

Code: Select all

#!/usr/bin/env python

import sys
import time
import io

def	lecture():
	# image read
	fichier=io.BytesIO()
	fichier=open("Impact2.jpg","rb")
	objet=fichier.read()
	fichier.close()

	return objet
and here is the function to capture a JPG image:

Code: Select all

#!/usr/bin/env python

import sys
import time
import io
import picamera


def 	lecture():
	# image capture

	my_stream=io.BytesIO()
	camera=picamera.PiCamera()
	camera.resolution=(640, 480)
	camera.capture(my_stream,format='jpeg')
	my_stream.seek(0)
	objet=my_stream.read()
	camera.close()

	return objet

Re: Display an image in Apache 2

Posted: Sat Sep 27, 2014 12:49 am
by DougieLawson
I'm not sure this is the best way. But I can fix this with: sudo chmod o+rwx /dev/vchiq.

It's not sticky across a reboot so it probably needs a UDEV rule to fix that.

sudo -i
echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
usermod -a -G video www-data
exit

Re: Display an image in Apache 2

Posted: Sat Sep 27, 2014 9:33 pm
by Tom T
Thank you Dougie,
With your solution, now I'm able to display an image with picamera in Apache 2.
Thank you again Dougie. :D