Open Jon007 opened 7 years ago
How about using four random cats as the group avatar?
Or one cat and one mystery men?
Or we create a mystery cat?
haha, i like both ideas.
Mystery Cat When the generation was slow, I tried to change the code to show a mystery cat on error. In this case I just picked a dark cat body template cat-generator-avatars/img/body_13.png which is ok but maybe yours is better. However I could never get the mystery cat to show up, as the code was just blocking and not actually erroring. That would be my idea for Mystery Cat, if file can't be generated for any reason (including disk full, directory not writable etc), then just show Mystery Cat. In this case build_monster is changed to return the cat url, and the places that call it change to use the url returned, eg:
private static function build_monster($seed=''){
try {
//make the cat
return plugins_url().'/cat-generator-avatars/'.$cachepath.''.$seed.'.png';
}
//catch exception
catch(Exception $e) {
return plugins_url().'/cat-generator-avatars/img/body_13.png?'. $e->getMessage();
}
}
Of course basic issues like cache directory missing or not writeable should also be checked on plugin activation.
Group Cat Four cats is also good for a group! Actually I was thinking a group avatar with 2 cats might be relatively easy:
Well that gets a unique 2 cat avatar for not much more processing than 1 normal cat avatar.
Agree with your both approaches.
For the mystery cat, how about we return all avatars as mystery cat, and then use js dynamic loading the actual images if exist on the disk, otherwise, call the server to create a new one. One concern is the performance, it may take several calls to retrieve the avatars.
I think the performance is fine now, trying to do something with JS would be very complex since there are many different types of screen where the avatar is called, in fact the plugin isn't in control of these screens to be able to inject js, remember there are comments, author meta, woocommerce comments, buddypress profile and user listing, ultimate member profile and listings, wordpress and theme user/profile, widgets etc etc.
I think the approach I suggested of generating the requested sizes as well as the original sizes can work, wordpress works in this way, and Google pagespeed likes the images to be the same size as they are shown to save some bandwidth, it seems a "correct" approach, I haven't had time to implement and test it though.
I just did some testing on slow shared hosting I use for backup, performance still fine for the avatar generation.
Some avatar plugins also provide default Avatars for buddypress groups. A single cat doesn't make sense as a group avatar though, it would be better overlay at least 2 cats...
The default BuddyPress group icon is 3 mystery men: https://buddypress.org/wp-content/plugins/buddypress/bp-core/images/mystery-group.png
The BuddyPress logo now uses 2 mystery men: https://ps.w.org/buddypress/assets/icon-256x256.png
So it could be possible to overlay 2 cats like the 2 mystery men. Or maybe the original illustrator would have an idea..