-
+
${profile.name}
${nip05Html}
@@ -211,6 +211,7 @@ function feedLinksHtml(profile: Profile) {
function profileMetaHtml(profile: Profile) {
return `
+
@@ -229,6 +230,7 @@ function articleMetaHtml(article: Article, profile: Profile) {
const imageUrl = article.image || profile.ogImageUrl;
return `
+
diff --git a/magick.ts b/magick.ts
index fdb7891..5603696 100644
--- a/magick.ts
+++ b/magick.ts
@@ -8,7 +8,7 @@ if (!magick) {
log("ImageMagick is not installed. Cannot generate preview images", "yellow")
}
-function createRoundedImage(profile: Profile) {
+function createProfileImage(profile: Profile) {
if (!magick || !profile.picture) return false;
const args = [
@@ -16,24 +16,44 @@ function createRoundedImage(profile: Profile) {
'-resize', '256x256^',
'-gravity', 'center',
'-extent', '256x256',
- '(', '+clone', '-alpha', 'extract',
- '-draw', "fill black polygon 0,0 0,128 128,0 fill white circle 128,128 128,0",
- '(', '+clone', '-flip', ')', '-compose', 'Multiply', '-composite',
- '(', '+clone', '-flop', ')', '-compose', 'Multiply', '-composite',
- ')',
- '-alpha', 'off',
- '-compose', 'CopyOpacity',
- '-composite',
- `${tmpImgDir}/p-${profile.event.id}-rounded.png`
+ `${tmpImgDir}/p-${profile.event.id}.png`
];
return runCommand(magick, args);
}
+async function createRoundedProfileImage(profile: Profile) {
+ if (!magick || !profile.picture) return false;
+
+ const status = await generateProfileImage(profile);
+
+ if (status && status.success) {
+ const args = [
+ `${tmpImgDir}/p-${profile.event.id}.png`,
+ '-resize', '256x256^',
+ '-gravity', 'center',
+ '-extent', '256x256',
+ '(', '+clone', '-alpha', 'extract',
+ '-draw', "fill black polygon 0,0 0,128 128,0 fill white circle 128,128 128,0",
+ '(', '+clone', '-flip', ')', '-compose', 'Multiply', '-composite',
+ '(', '+clone', '-flop', ')', '-compose', 'Multiply', '-composite',
+ ')',
+ '-alpha', 'off',
+ '-compose', 'CopyOpacity',
+ '-composite',
+ `${tmpImgDir}/p-${profile.event.id}-rounded.png`
+ ];
+
+ return runCommand(magick, args);
+ } else {
+ return false;
+ }
+}
+
async function createOgImage(profile: Profile, ogImagePath: string, backgroundColor: string) {
if (!magick) return false;
- const status = await createRoundedImage(profile);
+ const status = await createRoundedProfileImage(profile);
if (status && status.success) {
const args = [
@@ -51,6 +71,25 @@ async function createOgImage(profile: Profile, ogImagePath: string, backgroundCo
}
};
+export async function generateProfileImage(profile: Profile) {
+ if (!magick || !profile.picture) return false;
+
+ const imagePath = `${tmpImgDir}/p-${profile.event.id}.png`;
+ const fileExists = await checkFileExists(imagePath);
+
+ if (fileExists) {
+ return { success: true };
+ } else {
+ const status = await createProfileImage(profile);
+ if (status && status.success) {
+ log(`Created avatar image for ${profile.username}: ${imagePath}`, "blue")
+ return status;
+ } else {
+ log(`Could not create avatar image for ${profile.username}`, "yellow")
+ }
+ }
+}
+
export async function generateOgProfileImage(profile: Profile) {
if (!magick || !profile.picture) return false;
@@ -58,10 +97,13 @@ export async function generateOgProfileImage(profile: Profile) {
const backgroundColor = "#333333";
const fileExists = await checkFileExists(ogImagePath);
- if (!fileExists) {
+ if (fileExists) {
+ return { success: true };
+ } else {
const status = await createOgImage(profile, ogImagePath, backgroundColor);
if (status && status.success) {
log(`Created OG image for ${profile.username}: ${ogImagePath}`, "blue")
+ return status;
} else {
log(`Could not create OG image for ${profile.username}`, "yellow")
}
diff --git a/models/profile.ts b/models/profile.ts
index 05e5415..f213fa0 100644
--- a/models/profile.ts
+++ b/models/profile.ts
@@ -63,6 +63,14 @@ export default class Profile {
return `${config.base_url}/@${this.username}`;
}
+ get avatarImageUrl(): string {
+ if (magick) {
+ return `${config.base_url}/assets/g/img/p-${this.event.id}.png`;
+ } else {
+ return this.picture || "";
+ }
+ }
+
get ogImageUrl(): string {
if (magick) {
return `${config.base_url}/assets/g/img/og-p-${this.event.id}.png`;
diff --git a/server.ts b/server.ts
index ee7a02a..068437f 100644
--- a/server.ts
+++ b/server.ts
@@ -85,7 +85,6 @@ router.get("/:username/:identifier", async (ctx) => {
});
router.get("/assets/:path*", async (ctx) => {
- console.log(import.meta.dirname);
try {
let filePath = ctx.params.path || "";
let root: string;