simple-photo-gallery 2.0.16 → 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.cjs CHANGED
@@ -90,6 +90,30 @@ async function generateBlurHash(imagePath, componentX = 4, componentY = 3) {
90
90
  }
91
91
 
92
92
  // src/modules/build/utils/index.ts
93
+ function wrapText(text, maxCharsPerLine) {
94
+ const words = text.split(" ");
95
+ const lines = [];
96
+ let currentLine = "";
97
+ for (const word of words) {
98
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
99
+ if (word.length > maxCharsPerLine) {
100
+ if (currentLine) {
101
+ lines.push(currentLine);
102
+ currentLine = "";
103
+ }
104
+ lines.push(word);
105
+ } else if (testLine.length > maxCharsPerLine && currentLine) {
106
+ lines.push(currentLine);
107
+ currentLine = word;
108
+ } else {
109
+ currentLine = testLine;
110
+ }
111
+ }
112
+ if (currentLine) {
113
+ lines.push(currentLine);
114
+ }
115
+ return lines;
116
+ }
93
117
  async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPath, ui) {
94
118
  ui?.start(`Creating social media card image`);
95
119
  const headerBasename = path7__default.default.basename(headerPhotoPath, path7__default.default.extname(headerPhotoPath));
@@ -101,14 +125,38 @@ async function createGallerySocialMediaCardImage(headerPhotoPath, title, ouputPa
101
125
  const resizedImageBuffer = await image.resize(1200, 631, { fit: "cover" }).jpeg({ quality: 90 }).toBuffer();
102
126
  const outputPath = ouputPath;
103
127
  await sharp2__default.default(resizedImageBuffer).toFile(outputPath);
128
+ const CANVAS_WIDTH = 1200;
129
+ const CANVAS_HEIGHT = 631;
130
+ const FONT_SIZE = 72;
131
+ const MARGIN = 50;
132
+ const CHAR_WIDTH_RATIO = 0.6;
133
+ const usableWidth = CANVAS_WIDTH - 2 * MARGIN;
134
+ const maxCharsPerLine = Math.floor(usableWidth / (FONT_SIZE * CHAR_WIDTH_RATIO));
135
+ const lines = wrapText(title, maxCharsPerLine);
136
+ const lineHeight = FONT_SIZE * 1.2;
137
+ const totalTextHeight = FONT_SIZE + (lines.length - 1) * lineHeight;
138
+ const startY = CANVAS_HEIGHT - MARGIN - totalTextHeight + FONT_SIZE;
139
+ const leftX = MARGIN;
140
+ const tspanElements = lines.map((line, index) => {
141
+ const yPosition = startY + index * lineHeight;
142
+ const escapedLine = line.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
143
+ return `<tspan x="${leftX}" y="${yPosition}">${escapedLine}</tspan>`;
144
+ }).join("\n ");
104
145
  const svgText = `
105
- <svg width="1200" height="631" xmlns="http://www.w3.org/2000/svg">
146
+ <svg width="${CANVAS_WIDTH}" height="${CANVAS_HEIGHT}" xmlns="http://www.w3.org/2000/svg">
106
147
  <defs>
148
+ <linearGradient id="darkGradient" x1="0%" y1="0%" x2="0%" y2="100%">
149
+ <stop offset="0%" style="stop-color:rgb(0,0,0);stop-opacity:0" />
150
+ <stop offset="100%" style="stop-color:rgb(0,0,0);stop-opacity:0.65" />
151
+ </linearGradient>
107
152
  <style>
108
- .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; }
153
+ .title { font-family: 'Arial, sans-serif'; font-size: ${FONT_SIZE}px; font-weight: bold; fill: white; text-anchor: start; }
109
154
  </style>
110
155
  </defs>
111
- <text x="600" y="250" class="title">${title}</text>
156
+ <rect x="0" y="0" width="${CANVAS_WIDTH}" height="${CANVAS_HEIGHT}" fill="url(#darkGradient)" />
157
+ <text x="${leftX}" class="title">
158
+ ${tspanElements}
159
+ </text>
112
160
  </svg>
113
161
  `;
114
162
  const finalImageBuffer = await sharp2__default.default(resizedImageBuffer).composite([{ input: buffer.Buffer.from(svgText), top: 0, left: 0 }]).jpeg({ quality: 90 }).toBuffer();
@@ -1186,7 +1234,7 @@ async function waitForUpdateCheck(checkPromise) {
1186
1234
  // package.json
1187
1235
  var package_default = {
1188
1236
  name: "simple-photo-gallery",
1189
- version: "2.0.16"};
1237
+ version: "2.0.18"};
1190
1238
 
1191
1239
  // src/index.ts
1192
1240
  var program = new commander.Command();