ejabberd - Comments for "mod_vcard_odbc avatar manipulation" https://www.ejabberd.im/node/5024 en I've implemented the feature https://www.ejabberd.im/node/5024#comment-57967 <p>I've implemented the feature in mod_vcard. I imagine you can copy the code to mod_vcard_odbc with minor changes.</p> <p>This patch requires Imagemagick 'convert' program. It resizes all images to 80x80 pixels.</p> <pre> diff --git a/src/mod_vcard.erl b/src/mod_vcard.erl index 77dc30b..0b8abfb 100644 --- a/src/mod_vcard.erl +++ b/src/mod_vcard.erl @@ -198,7 +198,39 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) -&gt; IQ#iq{type = result, sub_el = Els} end. -set_vcard(User, LServer, VCARD) -&gt; +replace_binval(VCARD1, Photo2BinVal) -&gt; + {xmlelement, Name, Attrs, Els1} = VCARD1, + Els = replace_binval(["PHOTO", "BINVAL"], Photo2BinVal, Els1, []), + {xmlelement, Name, Attrs, Els}. + +replace_binval(_, _, [], Res) -&gt; + lists:reverse(Res); +replace_binval([], Photo2BinVal, [{xmlcdata, _Cdata} | Els], Res) -&gt; + [{xmlcdata, Photo2BinVal} | Res]++Els; +replace_binval([], _, _, Res) -&gt; + lists:reverse(Res); +replace_binval([Name | OtherNames], Photo2BinVal, [{xmlelement, Name, Attrs, SubEls1} | Els], Res) -&gt; + SubEls = replace_binval(OtherNames, Photo2BinVal, SubEls1, []), + El2 = {xmlelement, Name, Attrs, SubEls}, + [El2 | Res]++Els; +replace_binval(Names, Photo2BinVal, [El | Els], Res) -&gt; + replace_binval(Names, Photo2BinVal, Els, [El | Res]). + +set_vcard(User, LServer, VCARD1) -&gt; + Photo1BinVal = xml:get_path_s(VCARD1, [{elem, "PHOTO"}, {elem, "BINVAL"}, cdata]), + Photo1Img = jlib:decode_base64(Photo1BinVal), + F1n = "/tmp/ejabberd_vcard1_"++randoms:get_string(), + F2n = "/tmp/ejabberd_vcard2_"++randoms:get_string(), + {ok, F1d} = file:open(F1n, [write, binary]), + file:write(F1d, Photo1Img), + file:close(F1d), + os:cmd("convert " ++ F1n ++ " -resize 80x80 " ++ F2n), + {ok, Photo2Img} = file:read_file(F2n), + Photo2BinVal = jlib:encode_base64(binary_to_list(Photo2Img)), + VCARD = replace_binval(VCARD1, Photo2BinVal), + file:delete(F1n), + file:delete(F2n), + FN = xml:get_path_s(VCARD, [{elem, "FN"}, cdata]), Family = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "FAMILY"}, cdata]), Given = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "GIVEN"}, cdata]), </pre> Wed, 26 Oct 2011 19:08:05 +0000 mfoss comment 57967 at https://www.ejabberd.im