fix: watermark svg xlink, object-contain for vertical images, remove duplicate search form
This commit is contained in:
1 parent
986828893b
commit
7e85b35486
5 files changed
+20
-24
No files matched your search
@@ -118,31 +118,35 @@ async function watermarkedThumbnailResponse(thumbnail: ImmichBinary, assetId: st
|
||||
const targetWidth = 480;
|
||||
const resizedBuffer = await sharp(buffer)
|
||||
.resize({ width: targetWidth, withoutEnlargement: true })
|
||||
.toBuffer();
|
||||
|
||||
const resizedMetadata = await sharp(resizedBuffer).metadata();
|
||||
const width = resizedMetadata.width ?? targetWidth;
|
||||
const height = resizedMetadata.height ?? 300;
|
||||
|
||||
let watermarked = resizedBuffer;
|
||||
let watermarked = buffer;
|
||||
try {
|
||||
const logoPath = path.join(process.cwd(), "public", "brand", "logo-white.png");
|
||||
const logoBuffer = await fs.readFile(logoPath);
|
||||
|
||||
// Logo auf 60% der Bildbreite skalieren
|
||||
const logoTargetWidth = Math.round(width * 0.6);
|
||||
// Skaliere das Bild so, dass es in eine 800x800 Box passt (damit Hoch- und Querformat korrekt skaliert werden)
|
||||
const targetSize = 800;
|
||||
const resizedBuffer = await sharp(buffer)
|
||||
.resize({ width: targetSize, height: targetSize, fit: "inside", withoutEnlargement: true })
|
||||
.toBuffer();
|
||||
|
||||
const { width, height } = await sharp(resizedBuffer).metadata();
|
||||
|
||||
// Berechne Wasserzeichen-Größe (50% der Bildbreite, max 400px)
|
||||
const logoTargetWidth = Math.min(Math.floor((width ?? targetSize) * 0.5), 400);
|
||||
|
||||
const resizedLogo = await sharp(logoBuffer)
|
||||
.resize({ width: logoTargetWidth, withoutEnlargement: true })
|
||||
.toBuffer();
|
||||
|
||||
const logoBase64 = resizedLogo.toString("base64");
|
||||
|
||||
const logoMetadata = await sharp(resizedLogo).metadata();
|
||||
const logoBase64 = resizedLogo.toString("base64");
|
||||
const logoWidth = logoMetadata.width ?? logoTargetWidth;
|
||||
const logoHeight = logoMetadata.height ?? (logoTargetWidth / 2);
|
||||
|
||||
// XLink wird für librsvg (welches von sharp genutzt wird) zwingend benötigt
|
||||
const svgOverlay = `
|
||||
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
||||
<image href="data:image/png;base64,${logoBase64}" x="${(width - logoWidth) / 2}" y="${(height - logoHeight) / 2}" width="${logoWidth}" height="${logoHeight}" opacity="0.6"/>
|
||||
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<image xlink:href="data:image/png;base64,${logoBase64}" x="${((width ?? targetSize) - logoWidth) / 2}" y="${((height ?? targetSize) - logoHeight) / 2}" width="${logoWidth}" height="${logoHeight}" opacity="0.6"/>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
|
||||
Reference in new issue
Block a user