diff --git a/fhem/CHANGED b/fhem/CHANGED index ce84327f8..1f6b9e376 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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: 00_RSS: new img type SVG (forum #111271) - bugfix: 73_AutoShuttersControl: fix bug after privacyDown and open window - feature: 48_BlinkCamera: first step to support BlinkMini (no change possible) - feature: 82_LGTV_WebOS: add Spotify app support diff --git a/fhem/FHEM/02_RSS.pm b/fhem/FHEM/02_RSS.pm index 47622a321..3ed9527c9 100644 --- a/fhem/FHEM/02_RSS.pm +++ b/fhem/FHEM/02_RSS.pm @@ -11,6 +11,7 @@ package main; use strict; use warnings; use GD; +use Image::LibRSVG; use feature qw/switch/; use vars qw(%data); use HttpUtils; @@ -449,28 +450,8 @@ sub RSS_itemImg { return unless ( defined($arg) ); return if ( $arg eq "" ); my $I; - if ( $srctype eq "url" || $srctype eq "urlq" ) { - my $data; - 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 ( $srctype eq "file" ) { if ( $imgtype eq "gif" ) { $I = GD::Image->newFromGif($arg); } @@ -480,11 +461,28 @@ sub RSS_itemImg { elsif ( $imgtype eq "jpeg" ) { $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 { 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" ) { $I = GD::Image->newFromGifData($arg); } @@ -494,13 +492,19 @@ sub RSS_itemImg { elsif ( $imgtype eq "jpeg" ) { $I = GD::Image->newFromJpegData($arg); } + elsif ( $imgtype eq "svg" ) { + my $rsvg = new Image::LibRSVG(); + $rsvg->loadImageFromString($arg); + $I = GD::Image->newFromPngData($rsvg->getImageBitmap()); + } else { return; } } - else { - return; - } + + # If any of the cases above was true, we should have an image now. Otherwise return. + return if(!defined($I)); + eval { my ( $width, $height ) = $I->getBounds(); if ( $scale =~ s/([wh])([\d]*)/$2/ ) @@ -1395,7 +1399,7 @@ sub plotFromUrl(@) {
  • rect <x1> <y1> <x2> <y2> [<filled>]
    Draws a rectangle with corners at positions (<x1>, <y1>) and (<x2>, <y2>), which is filled if the <filled> parameter is set and not zero.
    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.

  • img <x> <y> <['w' or 'h']s> <imgtype> <srctype> <arg>
    Renders a picture at the - position (<x>, <y>). The <imgtype> is one of gif, jpeg, png. + position (<x>, <y>). The <imgtype> is one of gif, jpeg, png, svg. 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 or urlq, the picture is loaded from the URL <arg> (with or without logging the URL), if <srctype> is data, the picture @@ -1422,7 +1426,7 @@ sub plotFromUrl(@) { moveby 0 -25
    text x y "Another text"
    img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }
    - embed 0 0 2 absolute plot1 { plotFromUrl('mySVG') } + embed 0 0 2 absolute plot1 { plotFromUrl('mySVG') }
    embed 10 200 2 absolute iframe1 "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/9HShl_ufOFI\" frameborder=\"0\" allowfullscreen></iframe>"

    @@ -1437,6 +1441,11 @@ sub plotFromUrl(@) {

    This requires the perl module Image::LibRSVG and librsvg. Debian-based systems can install these with apt-get install libimage-librsvg-perl.

    + You can display colorful icons with using the function FW_makeImage from the FHEMWEB API: + + img 40 200 h40 svg data {FW_makeImage('clock@blue')} + + For HTML output, you can use plotFromURL(<name>[,<zoom>[,<offset>]]) instead.