00_RSS: new img type SVG (forum #111271)
git-svn-id: https://svn.fhem.de/fhem/trunk@21959 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 00_RSS: new img type SVG (forum #111271)
|
||||||
- bugfix: 73_AutoShuttersControl: fix bug after privacyDown and open window
|
- bugfix: 73_AutoShuttersControl: fix bug after privacyDown and open window
|
||||||
- feature: 48_BlinkCamera: first step to support BlinkMini (no change possible)
|
- feature: 48_BlinkCamera: first step to support BlinkMini (no change possible)
|
||||||
- feature: 82_LGTV_WebOS: add Spotify app support
|
- feature: 82_LGTV_WebOS: add Spotify app support
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use GD;
|
use GD;
|
||||||
|
use Image::LibRSVG;
|
||||||
use feature qw/switch/;
|
use feature qw/switch/;
|
||||||
use vars qw(%data);
|
use vars qw(%data);
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
@@ -449,28 +450,8 @@ sub RSS_itemImg {
|
|||||||
return unless ( defined($arg) );
|
return unless ( defined($arg) );
|
||||||
return if ( $arg eq "" );
|
return if ( $arg eq "" );
|
||||||
my $I;
|
my $I;
|
||||||
if ( $srctype eq "url" || $srctype eq "urlq" ) {
|
|
||||||
my $data;
|
if ( $srctype eq "file" ) {
|
||||||
if ( $srctype eq "url" ) {
|
|
||||||
$data = GetFileFromURL( $arg, 3, undef, 1 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$data = GetFileFromURLQuiet( $arg, 3, undef, 1 );
|
|
||||||
}
|
|
||||||
if ( $imgtype eq "gif" ) {
|
|
||||||
$I = GD::Image->newFromGifData($data);
|
|
||||||
}
|
|
||||||
elsif ( $imgtype eq "png" ) {
|
|
||||||
$I = GD::Image->newFromPngData($data);
|
|
||||||
}
|
|
||||||
elsif ( $imgtype eq "jpeg" ) {
|
|
||||||
$I = GD::Image->newFromJpegData($data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elsif ( $srctype eq "file" ) {
|
|
||||||
if ( $imgtype eq "gif" ) {
|
if ( $imgtype eq "gif" ) {
|
||||||
$I = GD::Image->newFromGif($arg);
|
$I = GD::Image->newFromGif($arg);
|
||||||
}
|
}
|
||||||
@@ -480,11 +461,28 @@ sub RSS_itemImg {
|
|||||||
elsif ( $imgtype eq "jpeg" ) {
|
elsif ( $imgtype eq "jpeg" ) {
|
||||||
$I = GD::Image->newFromJpeg($arg);
|
$I = GD::Image->newFromJpeg($arg);
|
||||||
}
|
}
|
||||||
|
elsif ( $imgtype eq "svg" ) { # SVG: replace $arg with PNG data and act as if "png data" were given.
|
||||||
|
my $rsvg = new Image::LibRSVG();
|
||||||
|
$rsvg->loadImage($arg);
|
||||||
|
$arg = $rsvg->getImageBitmap();
|
||||||
|
$imgtype = "png";
|
||||||
|
$srctype = "data";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $srctype eq "data" ) {
|
elsif ( $srctype eq "url" || $srctype eq "urlq" ) { # URL: replace $arg with data and act as if "data" were given
|
||||||
|
if ( $srctype eq "url" ) {
|
||||||
|
$arg = GetFileFromURL( $arg, 3, undef, 1 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$arg = GetFileFromURLQuiet( $arg, 3, undef, 1 );
|
||||||
|
}
|
||||||
|
$srctype = "data";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $srctype eq "data" ) { # No elsif here, run this also if we saved data in $arg above.
|
||||||
if ( $imgtype eq "gif" ) {
|
if ( $imgtype eq "gif" ) {
|
||||||
$I = GD::Image->newFromGifData($arg);
|
$I = GD::Image->newFromGifData($arg);
|
||||||
}
|
}
|
||||||
@@ -494,13 +492,19 @@ sub RSS_itemImg {
|
|||||||
elsif ( $imgtype eq "jpeg" ) {
|
elsif ( $imgtype eq "jpeg" ) {
|
||||||
$I = GD::Image->newFromJpegData($arg);
|
$I = GD::Image->newFromJpegData($arg);
|
||||||
}
|
}
|
||||||
|
elsif ( $imgtype eq "svg" ) {
|
||||||
|
my $rsvg = new Image::LibRSVG();
|
||||||
|
$rsvg->loadImageFromString($arg);
|
||||||
|
$I = GD::Image->newFromPngData($rsvg->getImageBitmap());
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return;
|
# If any of the cases above was true, we should have an image now. Otherwise return.
|
||||||
}
|
return if(!defined($I));
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
my ( $width, $height ) = $I->getBounds();
|
my ( $width, $height ) = $I->getBounds();
|
||||||
if ( $scale =~ s/([wh])([\d]*)/$2/ )
|
if ( $scale =~ s/([wh])([\d]*)/$2/ )
|
||||||
@@ -1395,7 +1399,7 @@ sub plotFromUrl(@) {
|
|||||||
<li>rect <x1> <y1> <x2> <y2> [<filled>]<br>Draws a rectangle with corners at positions (<x1>, <y1>) and (<x2>, <y2>), which is filled if the <filled> parameter is set and not zero.<br>If x2 or y2 is preceeded with a + (plus sign) then the coordinate is relative to x1 or y1, or in other words, it is the width-1 or height-1 of the rectangle, respectively.</li><br>
|
<li>rect <x1> <y1> <x2> <y2> [<filled>]<br>Draws a rectangle with corners at positions (<x1>, <y1>) and (<x2>, <y2>), which is filled if the <filled> parameter is set and not zero.<br>If x2 or y2 is preceeded with a + (plus sign) then the coordinate is relative to x1 or y1, or in other words, it is the width-1 or height-1 of the rectangle, respectively.</li><br>
|
||||||
|
|
||||||
<li>img <x> <y> <['w' or 'h']s> <imgtype> <srctype> <arg> <br>Renders a picture at the
|
<li>img <x> <y> <['w' or 'h']s> <imgtype> <srctype> <arg> <br>Renders a picture at the
|
||||||
position (<x>, <y>). The <imgtype> is one of <code>gif</code>, <code>jpeg</code>, <code>png</code>.
|
position (<x>, <y>). The <imgtype> is one of <code>gif</code>, <code>jpeg</code>, <code>png</code>, <code>svg</code>.
|
||||||
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 <code>file</code>, the picture
|
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 <code>file</code>, the picture
|
||||||
is loaded from the filename <arg>, if <srctype> is <code>url</code> or <code>urlq</code>, the picture
|
is loaded from the filename <arg>, if <srctype> is <code>url</code> or <code>urlq</code>, the picture
|
||||||
is loaded from the URL <arg> (with or without logging the URL), if <srctype> is <code>data</code>, the picture
|
is loaded from the URL <arg> (with or without logging the URL), if <srctype> is <code>data</code>, the picture
|
||||||
@@ -1422,7 +1426,7 @@ sub plotFromUrl(@) {
|
|||||||
moveby 0 -25<br>
|
moveby 0 -25<br>
|
||||||
text x y "Another text"<br>
|
text x y "Another text"<br>
|
||||||
img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }<br>
|
img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }<br>
|
||||||
embed 0 0 2 absolute plot1 { plotFromUrl('mySVG') }
|
embed 0 0 2 absolute plot1 { plotFromUrl('mySVG') }<br>
|
||||||
embed 10 200 2 absolute iframe1 "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/9HShl_ufOFI\" frameborder=\"0\" allowfullscreen></iframe>"
|
embed 10 200 2 absolute iframe1 "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/9HShl_ufOFI\" frameborder=\"0\" allowfullscreen></iframe>"
|
||||||
</code>
|
</code>
|
||||||
<p>
|
<p>
|
||||||
@@ -1437,6 +1441,11 @@ sub plotFromUrl(@) {
|
|||||||
<p>
|
<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>.<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>.<p>
|
||||||
|
|
||||||
|
You can display colorful icons with using the function <code>FW_makeImage</code> from the <a href="http://wiki.fhem.de/wiki/DevelopmentFHEMWEB-API#FW_makeImage">FHEMWEB API</a>:
|
||||||
|
<code>
|
||||||
|
img 40 200 h40 svg data {FW_makeImage('clock@blue')}
|
||||||
|
</code>
|
||||||
|
|
||||||
For HTML output, you can use <code>plotFromURL(<name>[,<zoom>[,<offset>]])</code> instead.
|
For HTML output, you can use <code>plotFromURL(<name>[,<zoom>[,<offset>]])</code> instead.
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user