From 209356b8ade1920b50d1d3a1a5e121c6623d167b Mon Sep 17 00:00:00 2001 From: Minteck Date: Fri, 11 Nov 2022 23:47:49 +0100 Subject: Update --- includes/assets.inc | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'includes/assets.inc') diff --git a/includes/assets.inc b/includes/assets.inc index 9a0a9ac..3f9971a 100644 --- a/includes/assets.inc +++ b/includes/assets.inc @@ -11,14 +11,18 @@ function downloadAssets($system) { if (isset($general["avatar_url"])) { $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); echo(" /avatars/$id.webp\n"); - exec("convert -resize 512x512 \"" . $general["avatar_url"] . "\" ../assets/avatars/" . $id . ".webp"); - exec("convert -resize 512x512 \"" . $general["avatar_url"] . "\" ../assets/uploads/" . ($id === "gdapd" ? "raindrops" : "cloudburst") . ".png"); + file_put_contents("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION), file_get_contents($general['avatar_url'])); + exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION) . "\" ../assets/avatars/" . $id . ".webp"); + exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION) . "\" ../assets/uploads/" . ($id === "gdapd" ? "raindrops" : "cloudburst") . ".png"); + unlink("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION)); } if (isset($general["banner"])) { $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); echo(" /banners/$id.webp\n"); - exec("convert -resize 2048x2048 \"" . $general["banner"] . "\" ../assets/banners/" . $id . ".webp"); + file_put_contents("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION), file_get_contents($general['banner'])); + exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION) ."\" ../assets/banners/" . $id . ".webp"); + unlink("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION)); } $members = json_decode(file_get_contents("./data/$system/members.json"), true); @@ -28,12 +32,30 @@ function downloadAssets($system) { if (isset($member["avatar_url"])) { echo(" /avatars/$id.webp\n"); - exec("convert -resize 512x512 \"" . $member["avatar_url"] . "\" ../assets/avatars/" . $id . ".webp"); + file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url'])); + exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" ../assets/avatars/" . $id . ".webp"); + unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION)); } + echo(" /banners/$id.webp\n"); + if (isset($member["banner"])) { - echo(" /banners/$id.webp\n"); - exec("convert -resize 2048x2048 \"" . $member["banner"] . "\" ../assets/banners/" . $id . ".webp"); + file_put_contents("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION), file_get_contents($member['banner'])); + exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION) . "\" ../assets/banners/" . $id . ".webp"); + unlink("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION)); + } else { + $img = imagecreate(2048, 1024); + + if (isset($member["color"])) { + imagecolorallocate($img, hexdec(substr($member["color"], 0, 2)) / 2, hexdec(substr($member["color"], 2, 2)) / 2, hexdec(substr($member["color"], 4, 2)) / 2); + } else { + imagecolorallocate($img, 0, 0, 0); + } + + imagejpeg($img, "/tmp/img.jpeg", 100); + imagedestroy($img); + exec("convert -resize 2048x2048 \"/tmp/img.jpeg\" ../assets/banners/" . $id . ".webp"); + unlink("/tmp/img.jpeg"); } if (file_exists("../assets/uploads/pt-" . $member["name"] . ".png")) { -- cgit