how to get a snapshot using php for dahua SD49225T-HN

wozzzzza

Getting the hang of it
Joined
Jan 5, 2015
Messages
385
Reaction score
82
ah ha, worked it out. i have PHP version 5.4 on my local computer, V5.3 on the webserver i use, arrays are handled differently between 5.4 and 5.3, in 5.3 arrays are handled like this
PHP:
$cam_list=[
  1 => '192.168.1.xxx',
  2 => '192.168.1.xxx',
];
in version 5.4 they are only handled like this and above throws an error.
PHP:
$cam_list=array(
  1 => '192.168.1.xxx',
  2 => '192.168.1.xxx',
);
 

kokos1405

n3wb
Joined
Dec 2, 2015
Messages
2
Reaction score
0
Another way using curl:

Code:
<!DOCTYPE html>
<html>
<head>
<title>Dog Dog Cam</title>
</head>
<body>
<?php
$login = 'dookiehead';
$password = 'putsomestuffhereithink';
$url = 'http://10.0.0.65/cgi-bin/snapshot.cgi';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);
$im = imagecreatefromstring($result);
$now = date("U");
$newfile = "/tmp/$now.jpg";
file_put_contents($newfile, $orig);
$newnew = imagecreatetruecolor(960,540);
imagecopyresized($newnew, $im, 0, 0, 0, 0, 960, 540, 1920, 1080);
$newnewfile = "/var/www/tires/dogdog/images/$now-r.jpg";
imagejpeg($newnew, $newnewfile);
imagedestroy($im);
imagedestroy($newnew);
echo "<img src=\"images/$now-r.jpg\">";
?>
</body>
</html>
?>

How can i modify this code to use it for only saving the image at original size?
I want to grab the image only and save it.
Any help appreciated.
 

Go3Team

Pulling my weight
Joined
Mar 13, 2017
Messages
147
Reaction score
110
Location
RVA
How can i modify this code to use it for only saving the image at original size?
I want to grab the image only and save it.
Any help appreciated.
Try this:

Code:
<!DOCTYPE html>
<html>
<head>
<title>Dog Dog Cam</title>
</head>
<body>
<?php
$login = 'dookiehead';
$password = 'putsomestuffhereithink';
$url = 'http://10.0.0.65/cgi-bin/snapshot.cgi';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);
$im = imagecreatefromstring($result);
$now = date("U");
$newfile = "/tmp/$now.jpg";
file_put_contents($newfile, $orig);
$newnew = imagecreatetruecolor(1920,1080);
$newnewfile = "/var/www/tires/dogdog/images/$now-r.jpg";
imagejpeg($newnew, $newnewfile);
imagedestroy($im);
imagedestroy($newnew);
echo "<img src=\"images/$now-r.jpg\">";
?>
</body>
</html>
?>
 

luizmb

n3wb
Joined
Jun 11, 2022
Messages
2
Reaction score
0
Location
Sao Paulo, Brazil
i´m get this error

PHP Warning: imagecreatefromstring(): Data is not in a recognized format in C:\xampp\htdocs\yeson\facecapture_curl_v2.php on line 36

My cam is started, capture, return binary data but the code return his error

The cod part is

$result = curl_exec($curl); -- ok and return binary data
curl_close($curl); -- ok
$im = imagecreatefromstring($result);
$now = date("U");
$newnew = imagecreatetruecolor(960,540);
imagecopyresized($newnew, $im, 0, 0, 0, 0, 960, 540, 1920, 1080);
$newnewfile = "face".$now.".jpg";
imagejpeg($newnew, $newnewfile);
imagedestroy($im);
imagedestroy($newnew);

Can u help me?
 
Top