Gravatar.com - Remote Service
The point (a.k.a. problem) is, that the resizing doesn't happen on your server. It happens on the server from gravatar:
http(s)://*.gravatar.com
See in source - by using a query argument called s
. So whatever you do, Gravatar will respond with a square image in the size between 1px and 2048px:
"$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}";
Gravatar has an API... which can't do that - sorry to disappoint you.
Solutions - Workarounds
So the only solution is CSS in that case - BUT ... you use completely different avatars with a filter:
return apply_filters( 'get_avatar', $avatar, $id_or_email, $size, $default, $alt );
So in theory (not tested) you could do something like the following:
add_filter( 'get_avatar', 'wpse139329ResizedAvatar', 10, 5 );
function wpse139329ResizedAvatar( $avatar, $id_or_email, $size, $default, $alt )
{
$newAvatar = wp_get_image_editor( $avatar );
if ( is_wp_error( $newAvatar ) )
return $avatar;
$newAvatar->resize( 500, 100, true );
$info = pathinfo( $avatar );
$newAvatar->save( $info['filename'].$info['extension'] );
return $newAvatar;
}
Anyway, it should work along above shown lines.
Drawbacks
The drawback will be, that core doesn't support anything aside from turning off Gravatars completely. The reason can simply be guessed: WordPress.com is owned by the same guy who owns Gravatar.com (and several other companies like Vaultpress). So you will be left with an Gravatar that is remote fetched (including the delay) from a server and won't be used at all then.
Thing's aren't that bad...
In fact the function get_gravatar()
is "pluggable":
if ( !function_exists( 'get_avatar' ) ) :
So if you overwrite it, you can replace it completely with a different method of displaying avatars for your users. Craft one yourself, grab a plugin that does it, etc.