Uploading Grayscale images causes the image to be darkened


Uploading a purely grayscale image causes the image to be darkened when displayed by discourse. This applies to images in posts, as well as images uploaded as avatars. for example, take this image:

This is much darker that the image is supposed to be. However, if I shift the R,G, or B value of a single pixel, it will display correctly. In this case, I have shifted the top left pixel from (172,172,172) to (173,172,172). This is the only change I have made between the source images.

Now, because of the R value being shifted in one pixel, the image is being displayed accurately.

Unfortunately, this fix is not reliable for avatars. Once the image is scaled down, the shifted pixel gets lost and the smaller image gets darkened again. As a result, you can end up with a grab bag of light and dark avatars. To make it work for avatars, you pretty much need to shift a region of pixels, instead of just a single pixel.

Uploading image makes it black (not darker!)
Discourse greyscale jpg avatar processing adds darkness?
Uploading transparent overlay .png comes out incorrect

Here’s an example of a user who tried uploading a grayscale avatar with a single altered pixel. Note the version in the usercard is lighter than the resized version next to the post:


Here is an example of an avatar that works successfully. The entire background on this image was shifted slightly using the technique described in the OP.

(Régis Hanol) #4

We’re using both ImageMagick and ImageOptim to make sure thumbnails are as small as possible

Not sure what’s causing the image to be darkened though :frowning:

  • GIF: convert in.gif -coalesce -gravity center -thumbnail 100x100^ -extent 100x100 -layers optimize out.gif
  • OTHER: convert in.png[0] -background transparent -gravity center -thumbnail 100x100^ -extent 100x100 -interpolate bicubic -unsharp 2x0.5+0.7+0 -quality 98 out.png

(Sam Saffron) #5

We have had a similar report of this in the past by @pakl I think did not get to the bottom of it yet, something about those command lines

(Jeff Atwood) #6

Dupe of

I will reclassify that bug since it is reported often enough to be, and seems legit.

(Jeff Atwood) #7