7

I decided I wanted to change my gravatar to be circular. I have it circular on my blog with css and prefer the effect so decided to use a bit of imagemagick to give my image a circular alpha channel (so I could have it on SO, e.t.c. as well). a couple of quick commands later I was sorted:

# crop to square 422x422 with 0x0 offset
convert mike_gravatar.jpeg -crop 422x422+0+0 mike_gravatar_square.jpeg
# give circular alpha channel around it NOTE this is for a 422x422 image (note the 211x211)
convert mike_gravatar_square.jpeg \( +clone -threshold -1 -negate -fill white -draw "circle 211,211,211,0" \) -alpha off -compose copy_opacity -composite mike_gravatar_circle.png

brilliant, now we just upload this to gravatar, I will have a nice circular cropped image and all will be well with the world.


as you have probably guessed from the question all is not well:

darkened gravatar image

ok, I must have clearly messed up my imagemagick and not checked that the before and after image are the same, reopen the images next to one another, and see that they are indeed the same. I try uploading again to gravatar and notice that they seem to process the images after the "cropping" stage, here is what it looks like in the browser after the file upload (before the cropping messes it up):

working gravatar picture

Alright, lets do some digging, someone else must have stumbled upon this before, so I have a look around and one lone soul in a desolate forum wasteland cries out. Now there is no response to this, but the relevant text is here:

It seems that if a photo or picture uploaded to Gravatar's cropper doesn't have jet black, it will auto-level the nearest grey to black and darken the whole image, including darkening whites into greys. Can confirm that this occurs with any PNG image that has a grey background or has a large enough proportion of it, whether or not it has 255 whites and regardless if it has alpha-blending or not

So it seems like I can fix this by putting in a single black pixel, that sounds alright so I try adding a black pixel, then a single black and a single white pixel, result:

goddammit gravatar

So basically now I'm out of ideas:

  • does anyone have any idea what post-processing gravatar does, so I can undo it or counteract it's effects with pre-processing?
  • is this "feature" documented anywhere, or can it be turned off, or gotten around?

I think it would be quite cool to preprocess the image to counteract the darkening they would do to it but that would require knowing exactly what they do in order to change things and obviously might not be possible (depends on the relative movement of each colour, I suppose)

EDIT:

I tried making an inverse image to see if it was basing the processing on the average or the extreme values and that was also darkened, it seems that it's more likely to be the average:

darkened inverse circle

Mike H-R
  • 7,726
  • 5
  • 43
  • 65

1 Answers1

3

Alright, I've got a solution that "worked for me" unfortunately it is just empirical and "good enough" (I'd quite like to check what's actually happening but unfortunately don't have any more time to devote to being nerd sniped) I'm gonna post what I did, what I think might have happened and how I think this should be solved if someone has enough time.

First off what I did, I simply tried whitening the image by random amounts, what ended up working was a gamma around 2

convert mike_gravatar_circle.png -gamma 2 mike_gravatar_circle_light_2.png

here is what the picture looks like both before and after processing by gravatar:

gravatar pic before processing gravatar pic after processing

I feel it's pretty ridiculous that I need to clobber my picture like I do on the left to make it look normal so I'm going to leave this question open to see if anyone can show me a better/cleaner way of doing this.

EDIT: forgot to mention my (completely unfounded) guesses as to how this should be solved. So my guess is that gravatar might try and make the average color of the image some type of midrange value (as that might seem sensible... I guess, I don't know) and picks up the alpha as being all white. trying some experiments to determine could be interesting, but only if they had an api to automate uploading and downloading the images or it would be painful effort, I'm looking forward to any suggestions as to what people think is happening.

Mike H-R
  • 7,726
  • 5
  • 43
  • 65
  • This looks like problems with ImageMagick. Recently it started assuming that grayscale images are in a linear colorspace rather than the sRGB colorspace (that is, gamma is off by a factor of 2.2). What version of ImageMagick (convert) did you use? Just type "convert" and look at the first line of output to find out. – Glenn Randers-Pehrson Jun 11 '14 at 16:30
  • @GlennRanders-Pehrson I have `6.8.9-1 Q16 x86_64` but the problem is I upload the image on the left in order to get gravatar to display the image on the right. I'm afraid I don't fully understand what you're saying about imagemagick, could you clarify? are you saying that while processing the image for cropping gravatar thinks that the image uses a linear colorscale so instead of just cropping it also applies a gamma conversion of 2.2 to it? wouldn't that lighten the image rather than darken it as it does? I'm sure I'm misunderstanding, but it sounds like you might be on the right track... – Mike H-R Jun 11 '14 at 16:36
  • To prevent "convert" from changing the colorspace, add an option to tell ImageMagick that your image is already in "sRGB" colorspace or already "RGB" (linear), whichever may be the case, e.g., "convert -set colorspace mike_gravatar.jpeg -crop 422x422+0+0 mike_gravatar_square.jpeg" and also add "-set colorspace sRGB" to the beginning of your second "convert" command. It would have been useful to have a copy of the actual "mike_gravatar.jpeg" image that you started with. – Glenn Randers-Pehrson Jun 11 '14 at 21:02
  • Hmmm, unfortunately adding `-set colorspace sRGB` at the start of each command immediately after convert didn't seem to help, did I misunderstand what I should be doing?. – Mike H-R Jun 11 '14 at 23:31
  • Also, if you want a picture that gravatar will make darker you could use the one [here](http://i.stack.imgur.com/ZkiLE.png) as that also gets darkened by gravatar (which means their operation isn't even idempotent!) – Mike H-R Jun 11 '14 at 23:35
  • Did you try both "-set colorspace sRGB" and "-set colorspace RGB"? I would have tried both if had access to your original JPEG. By the way, your IM-6.8.9-1 is pretty recent so that should be OK. We're at 6.8.9-3 now but I don't think anything in this area has changed. I'd also have tested with GraphicsMagick. – Glenn Randers-Pehrson Jun 12 '14 at 00:23