simple-photo-gallery 2.0.17 → 2.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -76,6 +76,30 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
76
76
  }
77
77
 
78
78
  // src/modules/build/utils/index.ts
79
+ function wrapText(text, maxCharsPerLine) {
80
+ const words = text.split(" ");
81
+ const lines = [];
82
+ let currentLine = "";
83
+ for (const word of words) {
84
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
85
+ if (word.length > maxCharsPerLine) {
86
+ if (currentLine) {
87
+ lines.push(currentLine);
88
+ currentLine = "";
89
+ }
90
+ lines.push(word);
91
+ } else if (testLine.length > maxCharsPerLine && currentLine) {
92
+ lines.push(currentLine);
93
+ currentLine = word;
94
+ } else {
95
+ currentLine = testLine;
96
+ }
97
+ }
98
+ if (currentLine) {
99
+ lines.push(currentLine);
100
+ }
101
+ return lines;
102
+ }
79
103
  async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
80
104
  ui?.start(`Creating social media card image`);
81
105
  const headerBasename = path7.basename(headerPhotoPath, path7.extname(headerPhotoPath));
@@ -87,14 +111,38 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
87
111
  const resizedImageBuffer = await image.resize(1200, 631, { fit: "cover" }).jpeg({ quality: 90 }).toBuffer();
88
112
  const outputPath = ouputPath;
89
113
  await sharp2(resizedImageBuffer).toFile(outputPath);
114
+ const CANVAS_WIDTH = 1200;
115
+ const CANVAS_HEIGHT = 631;
116
+ const FONT_SIZE = 72;
117
+ const MARGIN = 50;
118
+ const CHAR_WIDTH_RATIO = 0.6;
119
+ const usableWidth = CANVAS_WIDTH - 2 * MARGIN;
120
+ const maxCharsPerLine = Math.floor(usableWidth / (FONT_SIZE * CHAR_WIDTH_RATIO));
121
+ const lines = wrapText(title, maxCharsPerLine);
122
+ const lineHeight = FONT_SIZE * 1.2;
123
+ const totalTextHeight = FONT_SIZE + (lines.length - 1) * lineHeight;
124
+ const startY = CANVAS_HEIGHT - MARGIN - totalTextHeight + FONT_SIZE;
125
+ const leftX = MARGIN;
126
+ const tspanElements = lines.map((line, index) => {
127
+ const yPosition = startY + index * lineHeight;
128
+ const escapedLine = line.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
129
+ return `<tspan x="${leftX}" y="${yPosition}">${escapedLine}</tspan>`;
130
+ }).join("\n ");
90
131
  const svgText = `
91
- <svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
132
+ <svg width="${CANVAS_WIDTH}" height="${CANVAS_HEIGHT}" xmlns="http://www.w3.org/2000/svg">
92
133
  <defs>
134
+ <linearGradient id="darkGradient" x1="0%" y1="0%" x2="0%" y2="100%">
135
+ <stop offset="0%" style="stop-color:rgb(0,0,0);stop-opacity:0" />
136
+ <stop offset="100%" style="stop-color:rgb(0,0,0);stop-opacity:0.65" />
137
+ </linearGradient>
93
138
  <style>
94
- .title { font-family: 'Arial, sans-serif'; font-size: 96px; font-weight: bold; fill: white; stroke: black; stroke-width: 5; paint-order: stroke; text-anchor: middle; }
139
+ .title { font-family: 'Arial, sans-serif'; font-size: ${FONT_SIZE}px; font-weight: bold; fill: white; text-anchor: start; }
95
140
  </style>
96
141
  </defs>
97
- <text x="600" y="250" class="title">${title}</text>
142
+ <rect x="0" y="0" width="${CANVAS_WIDTH}" height="${CANVAS_HEIGHT}" fill="url(#darkGradient)" />
143
+ <text x="${leftX}" class="title">
144
+ ${tspanElements}
145
+ </text>
98
146
  </svg>
99
147
  `;
100
148
  const finalImageBuffer = await sharp2(resizedImageBuffer).composite([{ input: Buffer.from(svgText), top: 0, left: 0 }]).jpeg({ quality: 90 }).toBuffer();
@@ -1172,7 +1220,7 @@ async function waitForUpdateCheck(checkPromise) {
1172
1220
  // package.json
1173
1221
  var package_default = {
1174
1222
  name: "simple-photo-gallery",
1175
- version: "2.0.17"};
1223
+ version: "2.0.18"};
1176
1224
 
1177
1225
  // src/index.ts
1178
1226
  var program = new Command();