From c40c56e09bcf7f6e2b9566bc1da42638a4d1dab2 Mon Sep 17 00:00:00 2001
From: borisneubert <>
Date: Mon, 4 Nov 2013 17:07:29 +0000
Subject: [PATCH] integration of plotToPng() function and small adaptions to
RSS for ease of use in RSS feeds
git-svn-id: https://svn.fhem.de/fhem/trunk@4147 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/02_RSS.pm | 14 +++++++++++++-
fhem/FHEM/98_SVG.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 5e62ae130..2a18ca03a 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -16,6 +16,7 @@
selection
- feature: RSS amended (read image from pipe, scaling options, line width)
- feature: WWO Module by baumrasen
+ - feature: plotAsPng() in 98_SVG.pm (Boris & betateilchen)
- 2013-09-29 (5.5)
- feature: new module 55_PIFACE.pm added (betateilchen)
diff --git a/fhem/FHEM/02_RSS.pm b/fhem/FHEM/02_RSS.pm
index 99d53394b..e7a65a1cd 100644
--- a/fhem/FHEM/02_RSS.pm
+++ b/fhem/FHEM/02_RSS.pm
@@ -251,6 +251,7 @@ RSS_itemDate {
sub
RSS_itemImg {
my ($S,$x,$y,$scale,$imgtype,$srctype,$arg,%params)= @_;
+ return unless(defined($arg));
return if($arg eq "");
my $I;
if($srctype eq "url") {
@@ -275,6 +276,7 @@ RSS_itemImg {
return;
}
} elsif($srctype eq "data") {
+ require "98_SVG.pm"; # enable use of plotAsPng()
if($imgtype eq "gif") {
$I= GD::Image->newFromGifData($arg);
} elsif($imgtype eq "png") {
@@ -658,7 +660,7 @@ RSS_CGI(){
The picture is scaled by the factor <s> (a decimal value). If 'w' or 'h' is in front of scale-value the value is used to set width or height to the value in pixel. If <srctype> is file
, the picture
is loaded from the filename <arg>, if <srctype> is url
, the picture
is loaded from the URL <arg>, if <srctype> is data
, the picture
- is loaded from Data <arg>. You can use
+ is piped in from data <arg>. You can use
{ <perl special> }
for <arg>. See below for example.
Notice: do not load the image from URL that is served by fhem as it leads to a deadlock.
@@ -674,6 +676,16 @@ RSS_CGI(){
text 0.10 0.95 { ReadingsVal("MyWeather","temperature","?"). "C" }
img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }
+
+ + Special uses
+
+ You can display SVG plots with the aid of the helper function plotAsPng()
(in 98_SVG.pm). Example:
+
+ img 20 30 0.6 png data { plotAsPng("mySVGPlot") }
+
+
+ This requires the perl module Image::LibRSVG and librsvg. Debian-based systems can install these with apt-get install libimage-librsvg-perl
.
diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm
index 8ee7d75bd..0d62bd6b4 100755
--- a/fhem/FHEM/98_SVG.pm
+++ b/fhem/FHEM/98_SVG.pm
@@ -1480,8 +1480,53 @@ SVG_pO($)
$SVG_RET .= "\n";
}
+##################
+
+# this is a helper function which creates a PNG image from a given plot
+sub plotAsPng(@) {
+ my (@plotName) = @_;
+ my (@webs, $mimetype, $svgdata, $rsvg, $pngImg);
+
+ @webs=devspec2array("TYPE=FHEMWEB");
+ foreach(@webs) {
+ if(!InternalVal($_,'TEMPORARY',undef)) {
+ $FW_wname=InternalVal($_,'NAME','');
+ last;
+ }
+ }
+ Debug "FW_wname= $FW_wname, plotName= $plotName[0]";
+
+ $FW_RET = undef;
+ $FW_webArgs{dev} = $plotName[0];
+ $FW_webArgs{logdev} = InternalVal($plotName[0], "LOGDEVICE", "");
+ $FW_webArgs{gplotfile} = InternalVal($plotName[0], "GPLOTFILE", "");
+ $FW_webArgs{logfile} = InternalVal($plotName[0], "LOGFILE", "CURRENT");
+ $FW_pos{zoom} = $plotName[1] if $plotName[1];
+ $FW_pos{off} = $plotName[2] if $plotName[2];
+
+ ($mimetype, $svgdata) = SVG_showLog("unused");
+
+ Debug "MIME type= $mimetype";
+ Debug "SVG= $svgdata";
+
+ eval {
+ require Image::LibRSVG;
+ $rsvg = new Image::LibRSVG();
+ $rsvg->loadImageFromString($svgdata);
+ $pngImg = $rsvg->getImageBitmap();
+ };
+ Debug "Error: $@" if($@);
+
+ return $pngImg if $pngImg;
+ return;
+}
+
+##################
+
1;
+##################
+
=pod
=begin html