# Uploading Grayscale images causes the image to be darkened

**URL:** https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616
**Category:** Bug
**Created:** [30 januari 2015 om 15:10 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616 "2015-01-30T15:10:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anon25879736](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon25879736](https://meta.discourse.org/u/anon25879736)
#### Post date: [30 januari 2015 om 15:10 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/1 "2015-01-30T15:10:34Z")

</div>

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:

![](https://global.discourse-cdn.com/meta/original/3X/c/3/c3371060c5a43fdaf8edf51ac4d2699f62bdec07.png)

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.

![](https://global.discourse-cdn.com/meta/original/3X/4/6/46e855c9528f8c55a640246e80a0a161f5786586.png)

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.

---

<div class="post-metadata">

### Author: ![anon25879736](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon25879736](https://meta.discourse.org/u/anon25879736)
#### Post date: [30 januari 2015 om 15:20 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/2 "2015-01-30T15:20:22Z")

</div>

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:

![](https://global.discourse-cdn.com/meta/original/3X/1/f/1fe7f95456b96fda3580684ee155045956708145.png)

---

<div class="post-metadata">

### Author: ![anon25879736](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon25879736](https://meta.discourse.org/u/anon25879736)
#### Post date: [30 januari 2015 om 15:24 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/3 "2015-01-30T15:24:37Z")

</div>

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.

![](https://global.discourse-cdn.com/meta/original/3X/4/5/455ac3d7988242b5af1942555e54a6975e359840.png)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [30 januari 2015 om 15:44 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/4 "2015-01-30T15:44:54Z")

</div>

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

> <https://github.com/discourse/discourse/blob/main/app/models/optimized_image.rb#L81-L115>

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

- 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`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [30 januari 2015 om 22:18 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/5 "2015-01-30T22:18:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [30 januari 2015 om 23:08 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/6 "2015-01-30T23:08:41Z")

</div>

Dupe of

[https://meta.discourse.org/t/discourse-gravatar-processing-screws-up-gamma/17993](https://meta.discourse.org/t/discourse-gravatar-processing-screws-up-gamma/17993)

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [30 januari 2015 om 23:08 UTC](https://meta.discourse.org/t/uploading-grayscale-images-causes-the-image-to-be-darkened/24616/7 "2015-01-30T23:08:44Z")

</div>


