2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

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
This commit is contained in:
borisneubert 2013-11-04 17:07:29 +00:00
parent a810e48b17
commit c40c56e09b
3 changed files with 59 additions and 1 deletions

View File

@ -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)

View File

@ -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 &lt;s&gt; (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 &lt;srctype&gt; is <code>file</code>, the picture
is loaded from the filename &lt;arg&gt;, if &lt;srctype&gt; is <code>url</code>, the picture
is loaded from the URL &lt;arg&gt;, if &lt;srctype&gt; is <code>data</code>, the picture
is loaded from Data &lt;arg&gt;. You can use
is piped in from data &lt;arg&gt;. You can use
<code>{ <a href="#perl">&lt;perl special&gt;</a> }</code> for &lt;arg&gt. See below for example.
Notice: do not load the image from URL that is served by fhem as it leads to a deadlock.<br></li>
<br>
@ -674,6 +676,16 @@ RSS_CGI(){
text 0.10 0.95 { ReadingsVal("MyWeather","temperature","?"). "C" }<br>
img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }<br>
</code>
<p>
<i>Special uses</i><p>
You can display <a href="#SVG">SVG</a> plots with the aid of the helper function <code>plotAsPng()</code> (in 98_SVG.pm). Example:<p>
<code>
img 20 30 0.6 png data { plotAsPng("mySVGPlot") }
</code>
<p>
This requires the perl module Image::LibRSVG and librsvg. Debian-based systems can install these with <code>apt-get install libimage-librsvg-perl</code>.
</ul>

View File

@ -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