Getting one white pixel along the height on picture when upgrading to 3.3

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
http://postimg.org/image/s11tyoub3/ this is how it looks after upgrading to 3.3, notice the white line on the right. Is it possible something went wrong during upgrade?

edit: original picture doesn't have white line, so its problem after resizing it to certain dimension. every image except original have white line

edit2: tried clearing images/thumbs folder and letting nop generate new thumbs, didnt working either

edit3: after clearing everything and restarting application some pictures have that white line some dont, still cant figure whats the problem... anyone have idea? please its huge issue
9 years ago
Hi fun123,

I've noticed that Nop resizes original square pictures (e.g. 125x125, target size 47)
to rectangular picture 47x46. One pixel is lost due to calculation problem
in CalculateDimensions method in PictureService, casting float to int.
The resulted image must be in square 47x47.
Dejan
9 years ago
I'm new to nop and started with v3.3 and noticed that I too have this issue.  The comment above was correct that it's a rounding bug in PictureService.cs.  Simply adding "Math.Round" in front of every cast to int solves the problem in my testing.  The code below correct the issue.

I haven't looked to see if there's already a report for this or if perhaps it's fixed in v3.4.


        protected virtual Size CalculateDimensions(Size originalSize, int targetSize,
            ResizeType resizeType = ResizeType.LongestSide, bool ensureSizePositive = true)
        {
            var newSize = new Size();
            switch (resizeType)
            {
                case ResizeType.LongestSide:
                    if (originalSize.Height > originalSize.Width)
                    {
                        // portrait
                        newSize.Width = (int)Math.Round(originalSize.Width * (float)(targetSize / (float)originalSize.Height));
                        newSize.Height = targetSize;
                    }
                    else
                    {
                        // landscape or square
                        newSize.Height = (int)Math.Round(originalSize.Height * (float)(targetSize / (float)originalSize.Width));
                        newSize.Width = targetSize;
                    }
                    break;
                case ResizeType.Width:
                    newSize.Height = (int)Math.Round(originalSize.Height * (float)(targetSize / (float)originalSize.Width));
                    newSize.Width = targetSize;
                    break;
                case ResizeType.Height:
                    newSize.Width = (int)Math.Round(originalSize.Width * (float)(targetSize / (float)originalSize.Height));
                    newSize.Height = targetSize;
                    break;
                default:
                    throw new Exception("Not supported ResizeType");
            }

            if (ensureSizePositive)
            {
                if (newSize.Width < 1)
                    newSize.Width = 1;
                if (newSize.Height < 1)
                    newSize.Height = 1;
            }

            return newSize;
        }
9 years ago
I just created a work item for this issue.  Please go and vote for it if you're impacted.
https://nopcommerce.codeplex.com/workitem/12218

Those of us that are using anything other than pure white for the background of thumbnails in CSS are likely experiencing it depending on the input/output dimensions that the resizing code works with.
9 years ago
Hey craig, thanks for answer we fixed it, i was wondering does the same thing happens when black pixels are added? I have problem specifically with .gif noimage available and it gets 1px black on right side again, but only at _125px?
Thanks once again
P.S. i fixed it by manually adding _125 thumb on ftp, but im just wondering in case this happens to large ammount of pictures
7 years ago
Problem solved. The implementation details can be found in the commit #63d7b3e
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.