4

Using the Mirror API, can animated GIF images be attached to the Glass timeline? If so, will they actually animate on Glass or present as a static image?

rymo
  • 3,285
  • 2
  • 36
  • 40

2 Answers2

5

Animated GIF images work both as attachment and as <img> tags in HTML.

Alain
  • 6,044
  • 21
  • 27
  • Using Mark's code below the GIF loads and animates perfectly, but I have had no luck getting the same image to work as an attachment. To eliminate my own code as a source of error, I tried modifying the HTML of the Quick Start example to post this GIF instead of the cat picture: the text shows large at the top of a black/transparent screen as if the image wasn't there at all. – rymo May 28 '13 at 23:15
  • I note that if I attach the GIF but with Content-type set to `image/png` or `image/jpeg`, Glass loads a single frame with no animation. Set properly to `image/gif`, the attachment is ignored. Running XE5 firmware, BTW. – rymo May 28 '13 at 23:21
  • three upvotes, but nobody can give a concrete example of an animated GIF working as an attachment? – rymo Jun 03 '13 at 21:52
3

To answer the second question the gif animates. I tested with a timeline card like this:

{
  "kind": "mirror#timelineItem",
  "id": "6fd3c490-f751-40e3-8e1f-8b71494160fc",
  "created": "2013-05-28T20:05:23.589Z",
  "updated": "2013-05-28T20:05:23.589Z",
  "etag": "\"r3ghbVW9Rp1kDP4UexS05_pFx4E/jVAhcX1aYFm8-1tN5G5Fv6RSscQ\"",
  "html": "<article class=\"photo\">\n  <img src=\"http://media.idownloadblog.com/wp-content/uploads/2012/05/Sonic-Animated.gif\" width=\"100%\" height=\"100%\">\n  <div class=\"photo-overlay\"></div>\n  <section>\n    <p class=\"text-auto-size\">Spring Fling Fundraiser at Filoli</p>\n  </section>\n</article>\n",
  "notification": {
    "level": "DEFAULT"
  }
}

And the gif animates on Glass. It did take a moment to download displaying the card with a generic gray image icon with the text on top at first, but once the image showed up it definitely is animated and looping. If you go back to it later it still animates.

Update - It is possible to animate an attached GIF with new help from Jenny Murphy over at the issue tracker. If you include very basic HTML that references the attachment (eg ) it does work and animate. I have verified this with Glass using XE6.

This is the java code to do so:

            TimelineItem timelineItem = new TimelineItem();
        timelineItem.setText("");
        timelineItem.setNotification(new NotificationConfig()
                .setLevel("DEFAULT"));
        //add html with reference to attachment using index 0
        timelineItem.setHtml("<img src=\"attachment:0\">");
        // Attach animated GIF
        String contentType = req.getParameter("contentType");
        URL url = new URL(req.getParameter("imageUrl"));
        byte[] b = ByteStreams.toByteArray(url.openStream());
        InputStream animatedGifStream = url.openStream();
        MirrorClient.insertTimelineItem(credential, timelineItem,
                contentType, animatedGifStream);

A full working implementation of this is at: https://github.com/mscheel/mirror-quickstart-java

That is the starter project for Java with extra features to attach a video or now an animated gif by attachment.

Mark Scheel
  • 2,963
  • 1
  • 20
  • 23
  • Inserting an animated GIF in an html card works, thank you. I still wish I could get it to work as an attachment... – rymo Jun 06 '13 at 18:05
  • See my edits in this answer, shows how to get it to work as an attachment, thanks Jenny Murphy for the pointer – Mark Scheel Jun 11 '13 at 15:55