Browse Source

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

Closes #456
Michael Bromley 5 years ago
parent
commit
3a16d879e9
1 changed files with 6 additions and 1 deletions
  1. 6 1
      packages/asset-server-plugin/src/sharp-asset-preview-strategy.ts

+ 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) {
                 return image.resize(maxWidth, maxHeight, { fit: 'inside' }).toBuffer();
             } else {
-                return data;
+                if (mimeType === 'image/svg+xml') {
+                    // Convert the SVG to a raster for the preview
+                    return image.toBuffer();
+                } else {
+                    return data;
+                }
             }
         } else {
             return sharp(path.join(__dirname, 'file-icon.png'))