Created
September 17, 2012 21:19
-
-
Save magicbug/3739873 to your computer and use it in GitHub Desktop.
PHP Code for overlaying logbook information on webcam image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 | |
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past | |
header('Content-Type: image/png'); | |
function LoadJpeg($imgname) | |
{ | |
/* Attempt to open */ | |
$im = @imagecreatefromjpeg($imgname); | |
/* See if it failed */ | |
if(!$im) | |
{ | |
/* Create a black image */ | |
$im = imagecreatetruecolor(150, 30); | |
$bgc = imagecolorallocate($im, 255, 255, 255); | |
$tc = imagecolorallocate($im, 0, 0, 0); | |
imagefilledrectangle($im, 0, 0, 150, 30, $bgc); | |
/* Output an error message */ | |
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); | |
} | |
$bgc = imagecolorallocate($im, 255, 255, 255); | |
$white = imagecolorallocatealpha($im, 255, 255, 255, 50); | |
$black = imagecolorallocatealpha($im, 0, 0, 0, 70); | |
// Draw a white rectangle | |
imagefilledrectangle($im, 1, 0, 640, 25, $white); | |
imagefilledrectangle($im, 1, 417, 640, 480, $black); | |
imagettftext($im, 12, 0, 5, 18, $ColorText, "/path/to/font/verdana.ttf", "2E0SQL Station IP Camera - ".date('d-m-y H:i')); | |
// Connect to logbook | |
$con = mysql_connect("localhost","username","password"); | |
if (!$con) | |
{ | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("database_name", $con); | |
$result = mysql_query("SELECT * FROM TABLE_HRD_CONTACTS_V01 ORDER BY COL_TIME_ON DESC LIMIT 5"); | |
$qsos .= ""; | |
while($row = mysql_fetch_array($result)) | |
{ | |
$timestamp = strtotime($row['COL_TIME_ON']); | |
$qsos .= date('d/m/y H:i', $timestamp)." ".$row['COL_CALL']." on ".$row['COL_BAND']." ".$row['COL_SAT_NAME']."\n"; | |
} | |
imagettftext($im, 8, 0, 5, 430, $bgc, "/path/to/font/verdana.ttf", $qsos); | |
return $im; | |
} | |
$img = LoadJpeg('shack.jpg'); | |
imagejpeg($img); | |
imagedestroy($img); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment