Initial CUSTOM_IMAGE commit

This commit is contained in:
ehpersonal38
2023-03-14 22:24:27 -04:00
parent aaffa6f5c5
commit 6638016546
5 changed files with 79 additions and 0 deletions
+7
View File
@@ -206,6 +206,13 @@ RAW_SPECTROGRAM=0
HEARTBEAT_URL=
## CUSTOM_IMAGE and CUSTOM_IMAGE_TITLE allow you to show a custom image on the
## Overview page of your BirdNET-Pi. This can be used to show a dynamically
## updating picture of your garden, for example.
CUSTOM_IMAGE=
CUSTOM_IMAGE_TITLE=
## These are just for debugging
LAST_RUN=
THIS_RUN=
+22
View File
@@ -211,6 +211,22 @@ if(isset($_GET['submit'])) {
$contents2 = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents2);
}
if(isset($_GET["custom_image"])) {
$custom_image = $_GET["custom_image"];
if(strcmp($custom_image,$config['CUSTOM_IMAGE']) !== 0) {
$contents = preg_replace("/CUSTOM_IMAGE=.*/", "CUSTOM_IMAGE=$custom_image", $contents);
$contents2 = preg_replace("/CUSTOM_IMAGE=.*/", "CUSTOM_IMAGE=$custom_image", $contents2);
}
}
if(isset($_GET["custom_image_label"])) {
$custom_image_label = $_GET["custom_image_label"];
if(strcmp($custom_image_label,$config['CUSTOM_IMAGE_TITLE']) !== 0) {
$contents = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents);
$contents2 = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents2);
}
}
$fh = fopen('/etc/birdnet/birdnet.conf', "w");
$fh2 = fopen("./scripts/thisrun.txt", "w");
fwrite($fh, $contents);
@@ -301,6 +317,12 @@ foreach($formats as $format){
<label for="raw_spectrogram">Minimalist Spectrograms: </label>
<input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> ><br>
<label for="custom_image">Custom Image Absolute Path: </label>
<input name="custom_image" type="text" value="<?php print($newconfig['CUSTOM_IMAGE']);?>"/><br>
<label for="custom_image_label">Custom Image Label: </label>
<input name="custom_image_label" type="text" value="<?php print($newconfig['CUSTOM_IMAGE_LABEL']);?>"/><br>
<h3>BirdNET-Lite Settings</h3>
<p>
+7
View File
@@ -233,6 +233,13 @@ SILENCE_UPDATE_INDICATOR=0
RAW_SPECTROGRAM=0
## CUSTOM_IMAGE and CUSTOM_IMAGE_TITLE allow you to show a custom image on the
## Overview page of your BirdNET-Pi. This can be used to show a dynamically
## updating picture of your garden, for example.
CUSTOM_IMAGE=
CUSTOM_IMAGE_TITLE=
## These are just for debugging
LAST_RUN=
THIS_RUN=
+35
View File
@@ -23,6 +23,20 @@ $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
$home = trim($home);
if(isset($_GET['custom_image'])){
if(isset($config["CUSTOM_IMAGE"])) {
?>
<br>
<h3><?php echo $config["CUSTOM_IMAGE_TITLE"]; ?></h3>
<?php
$image_data = file_get_contents($config["CUSTOM_IMAGE"]);
$image_base64 = base64_encode($image_data);
$img_tag = "<img src='data:image/png;base64," . $image_base64 . "'>";
echo $img_tag;
}
die();
}
if(isset($_GET['fetch_chart_string']) && $_GET['fetch_chart_string'] == "true") {
$myDate = date('Y-m-d');
$chart = "Combo-$myDate.png";
@@ -294,8 +308,11 @@ if (file_exists('./Charts/'.$chart)) {
$refresh = $config['RECORDING_LENGTH'];
$time = time();
echo "<img id=\"spectrogramimage\" src=\"/spectrogram.png?nocache=$time\">";
?>
<div id="customimage"></div>
</div>
</div>
@@ -372,6 +389,24 @@ window.addEventListener("load", function(){
window.setInterval(function(){
document.getElementById("spectrogramimage").src = "/spectrogram.png?nocache="+Date.now();
}, <?php echo $refresh; ?>*1000);
<?php if(isset($config["CUSTOM_IMAGE"])){?>
// every 1 second, this loop will run and refresh the custom image
window.setInterval(function(){
// Find the customimage element
var customimage = document.getElementById("customimage");
function updateCustomImage() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "overview.php?custom_image=true", true);
xhr.onload = function() {
customimage.innerHTML = xhr.responseText;
}
xhr.send();
}
updateCustomImage();
}, 1000);
<?php } ?>
</script>
<style>
+8
View File
@@ -174,5 +174,13 @@ if ! grep RAW_SPECTROGRAM /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "RAW_SPECTROGRAM=0" >> /etc/birdnet/birdnet.conf
fi
if ! grep CUSTOM_IMAGE /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "CUSTOM_IMAGE=" >> /etc/birdnet/birdnet.conf
fi
if ! grep CUSTOM_IMAGE_TITLE /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "CUSTOM_IMAGE_TITLE=" >> /etc/birdnet/birdnet.conf
fi
sudo systemctl daemon-reload
restart_services.sh