comparison mod_pep_vcard_png_avatar/mod_pep_vcard_png_avatar.lua @ 2496:e6a3bdbce7b9

mod_pep_vcard_png_avatar: Move to dwebp, handle errors on opening file_png.
author Michel Le Bihan <michel@lebihan.pl>
date Mon, 13 Feb 2017 21:50:53 +0100
parents 7be1ca7a51a4
children c22b6283d226
comparison
equal deleted inserted replaced
2495:5ca2470a7755 2496:e6a3bdbce7b9
116 local image=pep_photo:get_child_text("data", "urn:xmpp:avatar:data"); 116 local image=pep_photo:get_child_text("data", "urn:xmpp:avatar:data");
117 if pep_photo and metadata.attr.type == "image/webp" then 117 if pep_photo and metadata.attr.type == "image/webp" then
118 local file_webp = io.open("/tmp/Prosody_temp_avatar.webp", "w"); 118 local file_webp = io.open("/tmp/Prosody_temp_avatar.webp", "w");
119 file_webp:write(base64.decode(pep_photo:get_child_text("data", "urn:xmpp:avatar:data"))); 119 file_webp:write(base64.decode(pep_photo:get_child_text("data", "urn:xmpp:avatar:data")));
120 file_webp:close(); 120 file_webp:close();
121 os.execute("convert /tmp/Prosody_temp_avatar.webp /tmp/Prosody_temp_avatar.png"); 121 os.execute("dwebp /tmp/Prosody_temp_avatar.webp -o /tmp/Prosody_temp_avatar.png");
122 local file_png = io.open("/tmp/Prosody_temp_avatar.png", "r"); 122 local file_png = io.open("/tmp/Prosody_temp_avatar.png", "r");
123 image=base64.encode(file_png:read("*a")); 123 if file_png ~= nil then
124 file_png:close(); 124 image=base64.encode(file_png:read("*a"));
125 file_png:close();
126 else
127 module:log("error", "Couldn't access /tmp/Prosody_temp_avatar.png. Are you sure that /tmp is readable and writable and that Prosody can execute the dwebp command?");
128 end
125 os.remove("/tmp/Prosody_temp_avatar.webp"); 129 os.remove("/tmp/Prosody_temp_avatar.webp");
126 os.remove("/tmp/Prosody_temp_avatar.png"); 130 os.remove("/tmp/Prosody_temp_avatar.png");
127 end 131 end
128 local vcard = get_vcard(username); 132 local vcard = get_vcard(username);
129 local new_photo = st.stanza("PHOTO", { xmlns = "vcard-temp" }) 133 local new_photo = st.stanza("PHOTO", { xmlns = "vcard-temp" })