There is no built-in .NET functionality to resize a GIF file and keep its properties (for example, the delay between frames). In this case, only the first frame of the file is displayed. As a result, the animated GIF file might become not animated after resizing it using Sitecore.
using Microsoft.Extensions.DependencyInjection; using Sitecore.Abstractions; using Sitecore.DependencyInjection; using Sitecore.Diagnostics; using Sitecore.Resources.Media; using System; public class GifSkippingResizeProcessor : Sitecore.Resources.Media.ResizeProcessor { public ResizeProcessor() : base(ServiceLocator.ServiceProvider.GetRequiredService<BaseMediaManager>(), ServiceLocator.ServiceProvider.GetRequiredService<BaseLog>()) { } public new void Process(GetMediaStreamPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (!string.Equals(args.MediaData.MimeType, "image/gif", StringComparison.OrdinalIgnoreCase)) { base.Process(args); } } }
<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <getMediaStream> <processor patch:instead="*[@type='Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel']" type="Custom.Resources.Media.GifSkippingResizeProcessor, Custom.Assembly" resolve="true"/> </getMediaStream> </pipelines> </sitecore> </configuration>