Browse Source

fix(asset-server-plugin): Fix corrupt SVG previews

Closes #456
Michael Bromley 5 years ago
parent
commit
3a16d879e9

+ 6 - 1
packages/asset-server-plugin/src/sharp-asset-preview-strategy.ts

@@ -23,7 +23,12 @@ export class SharpAssetPreviewStrategy implements AssetPreviewStrategy {
             if (maxWidth < width || maxHeight < height) {
             if (maxWidth < width || maxHeight < height) {
                 return image.resize(maxWidth, maxHeight, { fit: 'inside' }).toBuffer();
                 return image.resize(maxWidth, maxHeight, { fit: 'inside' }).toBuffer();
             } else {
             } else {
-                return data;
+                if (mimeType === 'image/svg+xml') {
+                    // Convert the SVG to a raster for the preview
+                    return image.toBuffer();
+                } else {
+                    return data;
+                }
             }
             }
         } else {
         } else {
             return sharp(path.join(__dirname, 'file-icon.png'))
             return sharp(path.join(__dirname, 'file-icon.png'))