Author Topic: Help needed updating php webcam image rename script  (Read 425 times)

0 Members and 1 Guest are viewing this topic.

Offline WessexWeather

  • Senior Member
  • **
  • Posts: 54
    • WessexWeather
Help needed updating php webcam image rename script
« on: May 03, 2017, 03:24:52 PM »
Appealing to any php experts out there!

In this post...

http://www.wxforum.net/index.php?topic=23310.msg275076#msg275076

...PaulMy designed a nice php script to rename the latest time stamped webcam image uploaded by an IP camera, to a fixed filename to be displayed on a website: -

Quote
<?php
#############################################################################################################
## Script to rename Hikvision IP uploaded files containing date and time in file name to a new fixed filename
## Provided by morfeas2002  http://kalamata.meteoclub.gr/
## CAUTION this script will remove any ???.jpg uploaded files from the folder
## CAUTION
## CAUTION
## CAUTION this script will remove any ???.jpg uploaded files from the folder
#############################################################################################################
//date_default_timezone_set("Europe/London");
$dir = "/home/XXX/public_html/XXX/XXX/"; // change to suit your system relative to where this script is executed
$pattern = '\.(jpg)$';
//
$newstamp = 0;           
$newname = "";
//
if ($handle = opendir($dir)) {             
       while (false !== ($fname = readdir($handle)))  {           
         // Eliminate current directory, parent directory           
         if (ereg('^\.{1,2}$',$fname)) continue;           
         // Eliminate other pages not in pattern           
         if (! ereg($pattern,$fname)) continue;           
         // -------------
         //
         //
         //
         $pinakas[] = $fname;
       }
       //
       //
       sort($pinakas);
       //
       $posot = count($pinakas);
       //
       if ($posot>1) $newname = $pinakas[$posot-2];
       if ($posot==1) $newname = $pinakas[$posot-1];
}
closedir ($handle);
// $newname
//
copy("/home/XXX/public_html/XXX/XXX/$newname", "/home/XXX/public_html/XXX/XXX/webcamimage.jpg"); // change to suit your system relative to where this script is executed
//
$filesa = glob('/home/XXX/public_html/XXX/XXX/*.jpg'); // change to suit your system relative to where this script is executed
array_walk($filesa,'myunlink');
//
function myunlink($t)
   {
   unlink($t);
   }
//
?>

 It works well on older versions of php (albeit with ereg deprecation warnings) but with php 7.0 installed it throws up the following error: -

Quote
[03-May-2017 17:26:01 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function ereg() in /home/XXX/public_html/XXX/XXX/webcamimagerename.php:20
Stack trace:
#0 {main}
  thrown in /home/XXX/public_html/XXX/XXX/webcamimagerename.php on line 20

This may be due to the fact that ereg has been deprecated. Can anyone re-write this script to do the same thing in later versions of php, or suggest an alternative?

Many thanks in advance.

Cheers,

Simon (WessexWeather)


Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8483
    • Meteotemplate
Re: Help needed updating php webcam image rename script
« Reply #1 on: May 03, 2017, 03:29:42 PM »
Simon try this:

Code: [Select]
if (preg_match('/^\.{1,2}$/',$fname)) continue;   
and

Code: [Select]
if (! preg_match('/\.(jpg)$/',$fname)) continue;         

Offline WessexWeather

  • Senior Member
  • **
  • Posts: 54
    • WessexWeather
Re: Help needed updating php webcam image rename script
« Reply #2 on: May 03, 2017, 03:42:24 PM »
Hi Jachym,

Do you mean replace the two ereg lines with those two preg_match lines?
Cheers,

Simon (WessexWeather)


Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8483
    • Meteotemplate
Re: Help needed updating php webcam image rename script
« Reply #3 on: May 03, 2017, 03:42:44 PM »
Yes

Offline WessexWeather

  • Senior Member
  • **
  • Posts: 54
    • WessexWeather
Re: Help needed updating php webcam image rename script
« Reply #4 on: May 03, 2017, 04:02:09 PM »
Jachym...

You are a php genius!  =D&gt;
Cheers,

Simon (WessexWeather)


Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8483
    • Meteotemplate
Re: Help needed updating php webcam image rename script
« Reply #5 on: May 03, 2017, 04:33:32 PM »
Jachym...

You are a php genius!  =D&gt;

You're welcome

Offline WessexWeather

  • Senior Member
  • **
  • Posts: 54
    • WessexWeather
Re: Help needed updating php webcam image rename script
« Reply #6 on: May 06, 2017, 08:35:06 AM »
The whitebalance on my new cam isn't that great. It doesn't cope well with bright skies particularly.

I have been looking at Fred's ImageMagick Scripts, specifically his autowhite script: -

http://www.fmwconcepts.com/imagemagick/autowhite/index.php

I am no expert at php but is there any way this could be incorporated into my rename script?
Cheers,

Simon (WessexWeather)


Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8483
    • Meteotemplate
Re: Help needed updating php webcam image rename script
« Reply #7 on: May 06, 2017, 08:51:09 AM »
Hi Simon,
never worked with this before and not all servers will support this. You would also have to contact that guy because he wants everyone to contact him if they want to use this script.
More importantly however, I think the problem with WB is that for each image a different value will work. So you optimize the script for one image and it applies it to a different one and makes it even worse. If the brightness of the image changes during the day, then this is going to be a problem. If you make it darker, then it will be useful for bright images, but make darker images even darker and vice versa.

Offline Bushman

  • Forecaster
  • *****
  • Posts: 6596
    • Eagle Bay Weather
Re: Help needed updating php webcam image rename script
« Reply #8 on: May 06, 2017, 09:44:14 AM »
Contact the author ONLY if you are using his scripts in commercial (i.e. not free/personal) applications is what it says.  (Which is silly since IM is free and the  "scripts" are  not really scripts per se; no "magic" coding involved.  But I digress)

I sed IM a lot for aa gov't client.  Pretty easy to use in PHP, assuming you can install it on the server.  Example:

<?php
exec("/usr/bin/convert input.jpg -bordercolor black -border 10x10 output.jpg");
?>
<img src="output.jpg">

Uses the IM Convert module to create a bordered image.  Etc.