1

I am using ImageResizer in an EPiServer 9 setup, where I've used the following plugin: https://nuget.episerver.com/en/OtherPages/Package/?packageId=ImageResizer.Plugins.EPiServerBlobReader along with ImageResizer.NET 4.0.5. I am implementing an AngularJS directive, where it updates the size if the size of the image. This is the implementation

app.directive('responsiveImage', function ($window, $timeout) {
    //From http://stackoverflow.com/a/6021027 with small modifications
    var setWidth = function (uri, value) {
        var parameterName = 'width';
        //REGEX for locating current parameter
        var re = new RegExp('([?&])' + parameterName + '=.*?(&|$)', 'i');
        if (uri.match(re)) {
            //Replaces the current w parameter with the new value
            return uri.replace(re, '$1' + parameterName + '=' + value + '$2');
        } else {
            //Identify which seperator to use
            var separator = uri.indexOf('?') !== -1 ? '&' : '?';
            //Sets the w parameter
            return uri + separator + parameterName + '=' + value;
        }
    };

    return {
        restrict: 'A',
        scope: {
            imageUrl: '@responsiveImage'
        },
        link: function(scope, element) {
            var maxWidth = 0;
            var promise;

            var resizeImage = function (initialCall) {
                $timeout.cancel(promise);

                promise = $timeout(function () {
                    var widthOfElement = element.width();

                    //Only fetch new image if the size is bigger, no need to downscale
                    if (widthOfElement > maxWidth) {
                        maxWidth = widthOfElement;

                        if (element.is('img')) {
                            element.attr('src', setWidth(scope.imageUrl, widthOfElement));
                            element.css('width', '');
                        } else { //Assume it is background image
                            element.css('background-image', "url('" + setWidth(scope.imageUrl, widthOfElement) + "')");
                        }
                    }
                    //If the first call, do it instantly but otherwise wait to see if the user is done resizing the window
                }, initialCall ? 0 : 50);
            };

            //Initial call
            resizeImage(true);

            angular.element($window).on('resize', resizeImage);
        }
    }
});

However when I start with a small window and resize it upwards, it stops serving the correct image and serves one of the low resolution images.

In the tests I've made, it got stuck at e.g. 1204px width. After it got stuck per se, then even if I browse to the image by typing it into the address bar and changing the width parameter, it serves a lower resolution image than asked. The original image is 2880px wide. I've tested in both Firefox and Chrome.

Is this a known issue in ImageResizer.NET when requesting too often that it returns an earlier image, or is there something wrong in my approach?

Hykalos
  • 51
  • 2
  • 11
  • What are the URLs you are putting in the address bar? What are the contents of the ImageResizer diagnostics report? – Lilith River Feb 21 '17 at 01:45
  • In the end, I went with a less dynamic approach, but to answer the question: the urls where in short `path-to-image?w=width` where the width is just a non negative number – Hykalos Feb 22 '17 at 07:18
  • And despite an original width of 2880px, the images would not exceed a certain width? Did you check `/resizer.debug` to verify the SizeLimiting plugin wasn't configured? There's no known instance of this happening. – Lilith River Apr 05 '17 at 18:02
  • I must admit that I did not look through it. – Hykalos Apr 10 '17 at 13:47
  • @user2981411 https://stackoverflow.com/questions/51252296/documentation-on-how-to-use-imageflow – Lilith River Jul 19 '18 at 22:01

0 Answers0