1 package Thrasher
::Avatar
;
9 Thrasher::Avatar - common avatar manipulation code, including setting
14 Thrasher::Avatar manages the common bits of avatar code, including
15 setting them. It takes care of converting them into PNG avatars,
16 and firing a callback for plugins to catch.
18 The callback 'avatar_changed' is called, with: ($component, $user_jid,
19 $legacy_username, $raw_binary_data, $base64_data, $image_magick_image).
23 use Thrasher
::Callbacks
qw(callbacks);
24 use Thrasher
::Log
qw(:all);
26 use MIME
::Base64
qw(encode_base64);
32 our @EXPORT_OK = qw(set_avatar);
33 our %EXPORT_TAGS = (all
=> \
@EXPORT_OK);
35 # I realize later versions of Image::Magick can do this with the
36 # 'mime' attribute, but I don't want to require that recent of
44 # After $component, you give it a $binary_avatar_data
46 my $component = shift;
48 my $legacy_jid = shift;
49 my $avatar_binary = shift;
51 if (!defined($avatar_binary)) {
52 confess
"Undefined avatar being passed to set_avatar.";
55 my $image = Image
::Magick
->new;
56 if (my $res = $image->BlobToImage($avatar_binary)) {
57 log("While trying to load avatar for $jid, " .
58 "Image::Magick complained: $res. Skipped because "
59 ."we failed to determine a type for the image.");
63 if (!$image->Get('magick')) {
64 log("While trying to load avatar for $jid, "
65 ."Image::Magick failed to determine a type for "
66 ."the image. Skipped.");
70 if ($image->Get('magick') ne 'PNG') {
71 $image->Set(magick
=> 'PNG');
72 $avatar_binary = $image->ImageToBlob();
75 my $base64_binary = encode_base64
($avatar_binary);
77 $component->{protocol
}->{backend
}->set_avatar($jid, $legacy_jid,
80 callbacks
('avatar_changed', $component, undef,
82 $avatar_binary, $base64_binary, $image);