Page MenuHomePhabricator

Allow custom image generation when choosing a profile image
ClosedPublic

Authored by chad on Feb 28 2017, 6:55 AM.
Tags
None
Referenced Files
F12808769: D17430.id41924.diff
Wed, Mar 27, 8:53 PM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Unknown Object (File)
Fri, Mar 22, 5:07 AM
Subscribers

Details

Summary

Ref T10319. This swaps the default in the Picture Chooser to allow picking of the custom unique avatar. We're currently going with 100k unique possibilities. The logic roughly hashes a user name and picks an image pack, color, and border. Based on that, we select the first character of their username, or fall back to Psyduck if not [a-z][0-9].

Test Plan

Set the following usernames from ProfilePicture as a test: chad, epriestley, sally, 007, _cat_, -doggie-.

pasted_file (758×574 px, 98 KB)

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

  • build a fake default image before real one

Faked the profile image one for now. I think I need to take maybe another 1-2 hours at cutting out some of the lame colors. If we're doing color x color, we have a pretty big depth to work with. Not a fan of mustard avatars.

pasted_file (1×2 px, 225 KB)

chad edited the test plan for this revision. (Show Details)

I think this is ready for review.

  • recompress pngs
  • use different "defaults" for different packs
epriestley added inline comments.
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
61–67

I think this won't get the right result if the alpha part has a leading zero (like 0.3) or more than one digit (like .25).

Since nothing else calls getBorderMap(), can you just have it return values like these instead?

array(
  array(255, 255, 255, 0.3),
  // ...
);

Those should be easy to convert into either the r, g, b, a or rgba(r, g, b, a); forms.

73–80

I think all of these calls can fail and return false -- if they do, we should throw an exception.

87

This should have static or be called nonstatically (-> instead of ::).

156

(Can this be private?)

161

It doesn't matter in this case, but for consistency prefer phutil_utf8_strtoupper(). Plain old strtoupper() has some crazy behavior for some UTF8 inputs.

167–169

You should add some junk to the end of the username, or we'll always get the same value for a range with the same endpoints.

That is, if you digest "chad" into the range 1-10, let's say you get a 6 out.

Then you do:

$border_key = digest('chad', 1, 10);
$color_key = digest('chad', 1, 10);

Since the digest is stable, the border and color will always both be the same, 6. So there are only 10 possible border+color combinations, not 100 like you want.

You can fix this by digesting "chadborder" and "chadcolor" instead, like this:

$border_key = digest($username.'border', 1, 10);
$color_key = digest($username.'color', 1, 10);

Then you'll get two different results -- both still stable and only functions of the username, but no longer guaranteed to be the same value.

213–214

I can look at this, it sounds like a bug in FileFinder -- especially if only ., and not .., is appearing.

This revision is now accepted and ready to land.Mar 1 2017, 4:28 PM
chad marked 6 inline comments as done.
  • better seeding of username
  • check for gd fails
  • use raw rgba colors
This revision is now accepted and ready to land.Mar 1 2017, 6:48 PM
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
156

I call this for building a fake image in profile. I can change it if we don't need that later.

213–214

I'll hold this back then until we can fix that?

  • check existence of GD
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
68–72

These calls can each individually fail. This is only checking the last one -- the full set of checks is like:

$ok = imagefill(..);
if (!$ok) { throw }
$ok = imagesetthickness(...);
if (!$ok) { throw }
etc
etc

imagecreatefromstring() and imagecreatetruecolor() may also fail.

The full error-checking version of this will unfortunately be 100000 lines long and there's no real avoiding it

219–221

Should be fixed now.

This currently just generates on demand when a user goes to pick a new photo. I presume I should land this after release cut.

This revision was automatically updated to reflect the committed changes.