Simple Function with Umbraco and Image Processor has stopped after upgrade

282 views Asked by At

I'm maintaining an Umbraco site which contains a simple watermarking feature implemented in Image Processor. This is working in Umbraco 7.4.2, via a compiled library for which I do not have the source. After updating Umbraco to 7.12.3 it no longer works. I'm looking for a simple explanation or hints on what the cause may be.

The versions of ImageProcessor and ImageProcessor.Web are unchanged (2.6.2.25 & 4.9.3.25) and ImageProcessor.Web.Config (2.4.1.19) are unchanged.

It would appear to be implemented an entry in the \config\ImageProcessor\processing.config file as follows:

<processing preserveExifMetaData="false" fixGamma="false" interceptAllRequests="true">
<presets>
</presets>
<plugins>
<plugin name="SecurityWatermark" type="MMUmbracoLibrary.Imaging.Web.Processors.SecurityWatermark, MMUmbracoLibrary">
  <settings>
    <setting key="WatermarkVirtualPath" value="~/app_data/watermark.png" />
    </settings>

Looking at the library with DotPeek I see the source of the method is as follows:

    using ImageProcessor.Processors;
    using ImageProcessor.Web.Processors;
    using System.Text.RegularExpressions;

    namespace MMUmbracoLibrary.Imaging.Web.Processors
    {
      public class SecurityWatermark : IWebGraphicsProcessor
      {
        private static readonly Regex QueryRegex = new Regex(".+", RegexOptions.Compiled);

        public SecurityWatermark()
        {
          this.Processor = (IGraphicsProcessor) new MMUmbracoLibrary.Imaging.Processors.SecurityWatermark();
        }

        public Regex RegexPattern
        {
          get
          {
            return SecurityWatermark.QueryRegex;
          }
        }

        public int SortOrder
        {
          get
          {
            return 0;
          }
          private set
          {
          }
        }

        public IGraphicsProcessor Processor { get; private set; }

        public int MatchRegexIndex(string queryString)
        {
          return this.SortOrder;
        }
      }
    }

Also this code from DotPeek is the probably most significant part:

namespace MMUmbracoLibrary.Imaging.Processors
{
  public class SecurityWatermark : IGraphicsProcessor
  {
    public object DynamicParameter { get; set; }

    public Dictionary<string, string> Settings { get; set; }

    public Image ProcessImage(ImageFactory factory)
    {
      IMedia mediaByPath = ApplicationContext.Current.Services.MediaService.GetMediaByPath(HttpContext.Current.Request.Path);
      if (mediaByPath == null)
        throw new HttpException(404, "No image found");
      if ((int) mediaByPath.Properties["disableWatermark"].Value != 0)
        return factory.Image;
      string filename = HttpContext.Current.Server.MapPath(this.Settings["WatermarkVirtualPath"]);
      ImageLayer imageLayer = new ImageLayer()
      {
        Image = (Image) new Bitmap(filename),
        Opacity = 100,
        Size = factory.Image.Size
      };
      return factory.Overlay(imageLayer).Image;
    }
  }
}

To be honest this code doesn't make a lot of sense to me, but it seems to work. Can anyone suggest how an upgrade of Umbraco could have caused this to stop working?

0

There are 0 answers