02_RSS: support for more than one directory for background images
git-svn-id: https://svn.fhem.de/fhem/trunk@25031 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- feature: 02_RSS: support for more than one directory for background
|
||||
images
|
||||
- new: 50_Signalbot: Signal Messenger integration (official release)
|
||||
- feature: 57_Calender: limit specification when=... amended
|
||||
- change: 10_MQTT_BRIDGE: Move to deprecated
|
||||
|
||||
@@ -59,7 +59,7 @@ sub RSS_Initialize($) {
|
||||
|
||||
#$hash->{AttrFn} = "RSS_Attr";
|
||||
$hash->{AttrList} =
|
||||
"size itemtitle bg bgcolor tmin refresh areas autoreread:1,0 viewport noscroll urlOverride";
|
||||
"size itemtitle bgroot bg bgcolor tmin refresh areas autoreread:1,0 viewport noscroll urlOverride";
|
||||
$hash->{SetFn} = "RSS_Set";
|
||||
$hash->{NotifyFn} = "RSS_Notify";
|
||||
|
||||
@@ -931,8 +931,10 @@ sub RSS_returnIMG($$) {
|
||||
#
|
||||
# check if background directory is set
|
||||
my $reason = "?"; # remember reason for undefined image
|
||||
my $bgdir = AttrVal( $name, "bg", "undef" );
|
||||
if ( defined($bgdir) ) {
|
||||
my $bgroot = AttrVal( $name, "bgroot", "");
|
||||
my $bgdirs = AttrVal( $name, "bg", "undef" ); # comma-separated list of directories
|
||||
if ( defined($bgdirs) ) {
|
||||
|
||||
my $bgnr; # item number
|
||||
if ( defined( $defs{$name}{fhem} )
|
||||
&& defined( $defs{$name}{fhem}{bgnr} ) )
|
||||
@@ -958,67 +960,73 @@ sub RSS_returnIMG($$) {
|
||||
}
|
||||
|
||||
# detect pictures
|
||||
if ( opendir( BGDIR, $bgdir ) ) {
|
||||
my @bgfiles = grep { $_ !~ /^\./ } readdir(BGDIR);
|
||||
my @bgfiles;
|
||||
for my $bgdiritem (split(/,/, $bgdirs)) {
|
||||
my $bgdir= $bgroot . $bgdiritem;
|
||||
if ( opendir( BGDIR, $bgdir ) ) {
|
||||
push(@bgfiles, map { $bgdir . "/" . $_ } grep { $_ !~ /^\./ } readdir(BGDIR));
|
||||
closedir(BGDIR);
|
||||
} else {
|
||||
Log3 $name, 2, "$name: Cannot open directory $bgdiritem";
|
||||
}
|
||||
}
|
||||
#foreach my $f (@bgfiles) {
|
||||
# Debug sprintf("File \"%s\"\n", $f);
|
||||
#}
|
||||
|
||||
#foreach my $f (@bgfiles) {
|
||||
# Debug sprintf("File \"%s\"\n", $f);
|
||||
#}
|
||||
closedir(BGDIR);
|
||||
# get item number
|
||||
if ( $#bgfiles >= 0 ) {
|
||||
if ( $bgnr > $#bgfiles ) { $bgnr = 0; }
|
||||
$defs{$name}{fhem}{bgnr} = $bgnr;
|
||||
my $bgfile = $bgfiles[$bgnr];
|
||||
my $filetype = ( split( /\./, $bgfile ) )[-1];
|
||||
readingsSingleUpdate($defs{$name}, "bgFilename", $bgfile, 1);
|
||||
readingsSingleUpdate($defs{$name}, "bgFiletype", $filetype, 1);
|
||||
my $bg;
|
||||
$bg = newFromGif GD::Image($bgfile)
|
||||
if $filetype =~ m/^gif$/i;
|
||||
$bg = newFromJpeg GD::Image($bgfile)
|
||||
if $filetype =~ m/^jpe?g$/i;
|
||||
$bg = newFromPng GD::Image($bgfile)
|
||||
if $filetype =~ m/^png$/i;
|
||||
|
||||
# get item number
|
||||
if ( $#bgfiles >= 0 ) {
|
||||
if ( $bgnr > $#bgfiles ) { $bgnr = 0; }
|
||||
$defs{$name}{fhem}{bgnr} = $bgnr;
|
||||
my $bgfile = $bgdir . "/" . $bgfiles[$bgnr];
|
||||
my $filetype = ( split( /\./, $bgfile ) )[-1];
|
||||
readingsSingleUpdate($defs{$name}, "bgFilename", $bgfile, 1);
|
||||
readingsSingleUpdate($defs{$name}, "bgFiletype", $filetype, 1);
|
||||
my $bg;
|
||||
$bg = newFromGif GD::Image($bgfile)
|
||||
if $filetype =~ m/^gif$/i;
|
||||
$bg = newFromJpeg GD::Image($bgfile)
|
||||
if $filetype =~ m/^jpe?g$/i;
|
||||
$bg = newFromPng GD::Image($bgfile)
|
||||
if $filetype =~ m/^png$/i;
|
||||
if ( defined($bg) ) {
|
||||
my ( $bgwidth, $bgheight ) = $bg->getBounds();
|
||||
if ( $bgwidth != $width or $bgheight != $height ) {
|
||||
|
||||
if ( defined($bg) ) {
|
||||
my ( $bgwidth, $bgheight ) = $bg->getBounds();
|
||||
if ( $bgwidth != $width or $bgheight != $height ) {
|
||||
|
||||
# we need to resize
|
||||
my ( $w, $h );
|
||||
my ( $u, $v ) =
|
||||
( $bgwidth / $width, $bgheight / $height );
|
||||
if ( $u > $v ) {
|
||||
$w = $width;
|
||||
$h = $bgheight / $u;
|
||||
}
|
||||
else {
|
||||
$h = $height;
|
||||
$w = $bgwidth / $v;
|
||||
}
|
||||
$S->copyResized(
|
||||
$bg,
|
||||
( $width - $w ) / 2,
|
||||
( $height - $h ) / 2,
|
||||
0, 0, $w, $h, $bgwidth, $bgheight
|
||||
);
|
||||
# we need to resize
|
||||
my ( $w, $h );
|
||||
my ( $u, $v ) =
|
||||
( $bgwidth / $width, $bgheight / $height );
|
||||
if ( $u > $v ) {
|
||||
$w = $width;
|
||||
$h = $bgheight / $u;
|
||||
}
|
||||
else {
|
||||
# size is as required
|
||||
# kill the predefined image and take the original
|
||||
undef $S;
|
||||
$S = $bg;
|
||||
$h = $height;
|
||||
$w = $bgwidth / $v;
|
||||
}
|
||||
$S->copyResized(
|
||||
$bg,
|
||||
( $width - $w ) / 2,
|
||||
( $height - $h ) / 2,
|
||||
0, 0, $w, $h, $bgwidth, $bgheight
|
||||
);
|
||||
}
|
||||
else {
|
||||
# size is as required
|
||||
# kill the predefined image and take the original
|
||||
undef $S;
|
||||
$reason = "Something was wrong with background image \"$bgfile\".";
|
||||
$S = $bg;
|
||||
}
|
||||
}
|
||||
else {
|
||||
undef $S;
|
||||
$reason = "Something was wrong with background image \"$bgfile\".";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# evaluate layout
|
||||
#
|
||||
@@ -1219,8 +1227,14 @@ sub plotFromUrl(@) {
|
||||
by FHEMWEB file editor.</li><br>
|
||||
<li>size<br>The dimensions of the picture in the format
|
||||
<code><width>x<height></code>.</li><br>
|
||||
<li>bg<br>The directory that contains the background pictures (must be in JPEG, GIF or PNG format, file
|
||||
<li>bg<br>A comma-separated list of directories that contain the background pictures (must be in JPEG, GIF or PNG format, file
|
||||
format is guessed from file name extension).</li><br>
|
||||
<li>bgroot<br>A common prefix for all directories in the <code>bg</code> attribute. Needs to include a trailing path delimiter. Useful for
|
||||
setting subdirectories of a common root directory as background directories by only listing their names in the <code>bg</code> attributes
|
||||
and not the full paths.<br><br>
|
||||
Example 1: <code>attr myRSS bg /opt/fhem/PictureFrame/Bergansichten,/data/Files/Pictures</code><br>
|
||||
Example 2: <code>attr myRSS bgroot /opt/fhem/PictureFrame/; attr myRSS bg Bergansichten,Waldbilder</code><br>
|
||||
</li><br>
|
||||
<li>bgcolor <color><br>Sets the background color. </li><br>
|
||||
<li>tmin<br>The background picture is shown at least <code>tmin</code> seconds,
|
||||
no matter how frequently the RSS feed consumer accesses the page.</li><br>
|
||||
|
||||
Reference in New Issue
Block a user