{"id":1042,"date":"2017-03-17T14:24:50","date_gmt":"2017-03-17T14:24:50","guid":{"rendered":"http:\/\/sandjam.co.uk\/sandjam\/?p=1042"},"modified":"2018-08-03T13:50:12","modified_gmt":"2018-08-03T12:50:12","slug":"building-animated-gifs","status":"publish","type":"post","link":"https:\/\/sandjam.co.uk\/sandjam\/2017\/03\/building-animated-gifs\/","title":{"rendered":"Building animated gifs"},"content":{"rendered":"<p>I&#8217;ve recently spent some time on a project that involved generating and sharing some animated gifs and I thought I&#8217;d share some insights.<\/p>\n<h2>Technologies<\/h2>\n<p>The best tool I found for generating animated gifs is <a href=\"https:\/\/www.imagemagick.org\/script\/index.php\" target=\"_blank\" rel=\"noopener\">Imagemagick<\/a>. It&#8217;s a well established tool with a <a href=\"https:\/\/www.imagemagick.org\/script\/command-line-processing.php\" target=\"_blank\" rel=\"noopener\">command line<\/a> version and a <a href=\"http:\/\/php.net\/manual\/en\/book.imagick.php\" target=\"_blank\" rel=\"noopener\">PHP library<\/a> that allows you to programmatically create almost any type of image manipulation you might need.<\/p>\n<p>The only downside I could find in Imagemagick was that the animated gifs it outputs were quite large, and even using its own compression methods didn&#8217;t help a great deal. I solved this by running the results though <a href=\"https:\/\/www.lcdf.org\/gifsicle\/\" target=\"_blank\" rel=\"noopener\">Gifsicle<\/a> which is a popular choice for optimising animated gifs.<\/p>\n<p>Gifscicle has three options for compression which give different variations of speed to performance depending on your needs.<\/p>\n<h2>Sharing Gifs<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1044 alignleft\" src=\"https:\/\/sandjam.co.uk\/sandjam\/wp-content\/uploads\/2017\/03\/giphy.gif\" alt=\"\" width=\"240\" height=\"152\" \/><\/p>\n<p>We&#8217;ve all seen loads of examples of animated gifs shared on our Facebook and Twitter feeds and there are lots of gif search engines out there like <a href=\"http:\/\/gifly.com\/ve7X\/\" target=\"_blank\" rel=\"noopener\">Gifly<\/a>.<\/p>\n<p>I was surprised when I started looking in to these sites that lots of the time they aren&#8217;t actually showing you an animated gif but a mp4 video of it.<\/p>\n<p>This is because animated gifs really aren&#8217;t a very efficient format for displaying videos. The compression methods use aren&#8217;t nearly as effective as mp4 so a 5MB gif might only take 400Kb when encoded as a video.<\/p>\n<p>If you want to use open graph tags to share your gif with Facebook or Twitter you can&#8217;t add the gif path in to the og:image tag because it will only show the first frame of your animation. Instead you must convert it in to a video and use the <a href=\"https:\/\/developers.facebook.com\/docs\/sharing\/webmasters#media\" target=\"_blank\" rel=\"noopener\">og:video<\/a> tag on Facebook or the <a href=\"https:\/\/dev.twitter.com\/cards\/types\/player\" target=\"_blank\" rel=\"noopener\">Twitter Player Card<\/a> tags.<\/p>\n<h2>Converting GIFs to Video<\/h2>\n<p>I used the <a href=\"https:\/\/ffmpeg.org\/\" target=\"_blank\" rel=\"noopener\">FFmpeg<\/a> library to convert my animated gifs to mp4 video.<\/p>\n<p>FFmpeg is an amazingly powerful library and it&#8217;s always my first stop whenever I need to do anything to do with video manipulation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently spent some time on a project that involved generating and sharing some animated gifs and I thought I&#8217;d share some insights. Technologies The best tool I found for generating animated gifs is Imagemagick. It&#8217;s a well established tool with a command line version and a PHP library that allows you to programmatically create [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1043,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[23,16],"class_list":["post-1042","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","tag-social-networking","tag-video"],"acf":[],"_links":{"self":[{"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/posts\/1042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/comments?post=1042"}],"version-history":[{"count":4,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/posts\/1042\/revisions"}],"predecessor-version":[{"id":1078,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/posts\/1042\/revisions\/1078"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/media\/1043"}],"wp:attachment":[{"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/media?parent=1042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/categories?post=1042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sandjam.co.uk\/sandjam\/wp-json\/wp\/v2\/tags?post=1042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}