Use Kodi as a simple info radiator...
#1
Hi, here's a quick note on a technique I've been using for the last several months to use Kodi as an information radiator.

What I do is the following:
  • Generate the text I want to display, formated for display
  • Convert the text to an image
  • Copy the image to a folder I have shared as a web site
  • Send Kodi the URI of the image to display

The server I use is IIS and my code is C#, but there are dozens of ways to do this technique once it occurs to you.

As you can see from the code, I didn't try to solve too many problems here. You get one font size and a background color. More control would require code much more sophisticated than these simple scripts. Have fun with it. For me this works and I'm coding other stuff.

This method is code I found on the innertubes. I tweaked it a little, but didn't come up with it.

Code:
public static void CreateDashboardImage( string pText, string pFilepath, Color pBackgroundColor, int pFontSize )
{
    /* For use with Kodi use an aspect ration of 16/9 or 1.77.
     * An image that is 1080w x 607h will fill the screen. */
    // Load the original image
    var bitmap = new Bitmap( 1080, 607 );
    // Create a rectangle for the entire bitmap
    var rectanglef = new RectangleF( 0, 0, bitmap.Width, bitmap.Height );
    // Create graphic object that will draw onto the bitmap
    var g = Graphics.FromImage( bitmap );
    // Ensure the best possible quality rendering
    g.Clear( pBackgroundColor );
    g.SmoothingMode = SmoothingMode.AntiAlias;
    // The smoothing mode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing). One exception is that path gradient brushes do not obey the smoothing mode. Areas filled using a PathGradientBrush are rendered the same way (aliased) regardless of the SmoothingMode property.
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    // The interpolation mode determines how intermediate values between two endpoints are calculated.
    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
    // Use this property to specify either higher quality, slower rendering, or lower quality, faster rendering of the contents of this Graphics object.
    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; // This one is important
    // Create string formatting options (used for alignment)
    var format = new StringFormat()
    {
        Alignment = StringAlignment.Near,
        LineAlignment = StringAlignment.Near
    };
    // Draw the text onto the image
    g.DrawString( pText, new Font( "Lucida Sans Typewriter", pFontSize ), Brushes.Black, rectanglef, format );
    // Flush all graphics changes to the bitmap
    g.Flush();
    // Now save or use the bitmap
    bitmap.Save( pFilepath, ImageFormat.Jpeg );
    //image.Image = bitmap;
}

The code to send the image to Kodi is trivial:

Code:
private static void DisplayImageOnKodi( string pKodiLocation, string pImageUrl )
{
    KodiGetActivePlayers( pKodiLocation );
    // Todo: Check if player 2 is active, THEN call KodiBack()
    KodiBack( pKodiLocation );
    var kodiApi = pKodiLocation == "BEDROOM"
                      ? new Uri( "http://xx.xx.xx.xx:8080/jsonrpc?Player.Open" )
                      : new Uri( "http://xx.xx.xx.xx:8080/jsonrpc?Player.Open" );
    var requestJson = new JsonRpcDto
    {
        Method = "Player.Open",
        Params = new
        {
            item = new { file = pImageUrl }
        }
    };
    var json = JsonConvert.SerializeObject( requestJson );
    kodiApi.WebPostWithJsonParmsAsJson( json, new NetworkCredential( "user", "password" ) );
}

In the morning I have a wifi button (amazon dash) that has been hacked. The script associated with this button pulls the train schedule and the bus schedule and loads a table of times for my location and displays them on the TV and then begins a timer that updates the display ever 30 seconds for the next 5 minutes. Clicking the button a second time cancels the timer.

This technique could be used for lots of things.

Happy new year.
Reply

Logout Mark Read Team Forum Stats Members Help
Use Kodi as a simple info radiator...0