Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Lomaster

web cam + php

Recommended Posts

Caros colegas

preciso montar um sistema que tire foto via webcam e cadastre informações referentes a foto. Consegui algo parecido em Clique aqui. Funciona perfeitamente. Ele salva as fotos em uma pasta. Preciso no entanto, criar algo que eu possa dar um nome a esta foto e informar data em que foi tirada. Pelo que entendi no tutorial, a foto é capturada em arquivo flash e guardada em uma variável, no entanto não tenho conhecimento suficiente para desenvolver tal aplicação. Se alguém puder me orientar ficaría grato.

 

 

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Photobooth with PHP, jQuery and CSS3 | Tutorialzine Demo</title>

<link rel="stylesheet" type="text/css" href="assets/css/styles.css" />
<link rel="stylesheet" type="text/css" href="assets/fancybox/jquery.fancybox-1.3.4.css" />

</head>
<body>

<div id="topBar">
   <h1>jQuery & CSS3 Photobooth</h1>
   <h2>« Go back to Tutorialzine</h2>
</div>

<div id="photos"></div>

<div id="camera">
<span class="tooltip"></span>
<span class="camTop"></span>

   <div id="screen"></div>
   <div id="buttons">
   	<div class="buttonPane">
       	<a id="shootButton" href="" class="blueButton">Shoot!</a>
       </div>
       <div class="buttonPane hidden">
       	<a id="cancelButton" href="" class="blueButton">Cancel</a> <a id="uploadButton" href="" class="greenButton">Upload!</a>
       </div>
   </div>

   <span class="settings"></span>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="assets/fancybox/jquery.easing-1.3.pack.js"></script>
<script src="assets/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script src="assets/webcam/webcam.js"></script>
<script src="assets/js/script.js"></script>

</body>
</html>

upload.php

/*
This file receives the JPEG snapshot from
assets/webcam/webcam.swf as a POST request.
*/

// We only need to handle POST requests:
if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
exit;
}

$folder = 'uploads/';
$filename = md5($_SERVER['REMOTE_ADDR'].rand()).'.jpg';

$original = $folder.$filename;

// The JPEG snapshot is sent as raw input:
$input = file_get_contents('php://input');

if(md5($input) == '7d4df9cc423720b7f1f3d672b89362be'){
// Blank image. We don't need this one.
exit;
}

$result = file_put_contents($original, $input);
if (!$result) {
echo '{
	"error"		: 1,
	"message"	: "Failed save the image. Make sure you chmod the uploads folder and its subfolders to 777."
}';
exit;
}

$info = getimagesize($original);
if($info['mime'] != 'image/jpeg'){
unlink($original);
exit;
}

// Moving the temporary file to the originals folder:
rename($original,'uploads/original/'.$filename);
$original = 'uploads/original/'.$filename;

// Using the GD library to resize
// the image into a thumbnail:

$origImage	= imagecreatefromjpeg($original);
$newImage	= imagecreatetruecolor(154,110);
imagecopyresampled($newImage,$origImage,0,0,0,0,154,110,520,370); 

imagejpeg($newImage,'uploads/thumbs/'.$filename);

echo '{"status":1,"message":"Success!"

 

browse.php

/*
In this file we are scanning the image folders and
returning a JSON object with file names. It is used
by jQuery to display the images on the main page:
*/

// The standard header for json data:
header('Content-type: application/json');

$perPage = 24;

// Scanning the thumbnail folder for JPG images:
$g = glob('uploads/thumbs/*.jpg');

if(!$g){
$g = array();
}

$names = array();
$modified = array();

// We loop though the file names returned by glob,
// and we populate a second file with modifed timestamps.

for($i=0,$z=count($g);$i<$z;$i++){
$path = explode('/',$g[$i]);
$names[$i] = array_pop($path);

$modified[$i] = filemtime($g[$i]);
}

// Multisort will sort the array with the filenames
// according to their timestamps, given in $modified:

array_multisort($modified,SORT_DESC,$names);

$start = 0;

// browse.php can also paginate results with an optional
// GET parameter with the filename of the image to start from:

if(isset($_GET['start']) && strlen($_GET['start'])>1){
$start = array_search($_GET['start'],$names);

if($start === false){
	// Such a picture was not found
	$start = 0;
}
}

// nextStart is returned alongside the filenames,
// so the script can pass it as a $_GET['start']
// parameter to this script if "Load More" is clicked

$nextStart = '';

if($names[$start+$perPage]){
$nextStart = $names[$start+$perPage];
}

$names = array_slice($names,$start,$perPage);

// Formatting and returning the JSON object:

echo json_encode(array(
'files' => $names,
'nextStart'	=> $nextStart
));

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.