diff 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
line wrap: on
line diff
--- a/mod_pep_vcard_png_avatar/mod_pep_vcard_png_avatar.lua	Sun Feb 12 21:24:08 2017 +0100
+++ b/mod_pep_vcard_png_avatar/mod_pep_vcard_png_avatar.lua	Mon Feb 13 21:50:53 2017 +0100
@@ -118,10 +118,14 @@
 		local file_webp = io.open("/tmp/Prosody_temp_avatar.webp", "w");
 		file_webp:write(base64.decode(pep_photo:get_child_text("data", "urn:xmpp:avatar:data")));
 		file_webp:close();
-		os.execute("convert /tmp/Prosody_temp_avatar.webp /tmp/Prosody_temp_avatar.png");
+		os.execute("dwebp /tmp/Prosody_temp_avatar.webp -o /tmp/Prosody_temp_avatar.png");
 		local file_png = io.open("/tmp/Prosody_temp_avatar.png", "r");
-		image=base64.encode(file_png:read("*a"));
-		file_png:close();
+		if file_png ~= nil then
+			image=base64.encode(file_png:read("*a"));
+			file_png:close();
+		else
+			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?");
+		end
 		os.remove("/tmp/Prosody_temp_avatar.webp");
 		os.remove("/tmp/Prosody_temp_avatar.png");
 	end