Skip to content

Commit 0370dff

Browse files
committed
GetDimensionsFromSvg() should also consider viewBox attribute
1 parent 801e721 commit 0370dff

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/Libraries/SmartStore.Core/IO/ImageHeader.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public UnknownImageFormatException(string paramName = "", Exception e = null)
2929
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
3030
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
3131
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
32-
// { new byte[] { 0xff, 0xd8 }, DecodeJfif },
32+
//{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
3333
//{ new byte[] { 0xff, 0xd8, 0xff, 0xe0 }, DecodeJpeg },
3434
//{ new byte[] { 0xff }, DecodeJpeg2 },
3535
};
@@ -193,7 +193,21 @@ private static Size GetDimensionsFromSvg(Stream input)
193193
var width = reader["width"];
194194
var height = reader["height"];
195195

196-
return new Size(width.ToInt(), height.ToInt());
196+
var size = new Size(width.ToInt(), height.ToInt());
197+
if (size.Width == 0 || size.Height == 0)
198+
{
199+
var viewBox = reader["viewBox"];
200+
if (viewBox.HasValue())
201+
{
202+
var arrViewBox = viewBox.Trim().Split(' ');
203+
if (arrViewBox.Length == 4)
204+
{
205+
size = new Size(arrViewBox[2].ToInt(), arrViewBox[3].ToInt());
206+
}
207+
}
208+
}
209+
210+
return size;
197211
}
198212
}
199213
}

src/Libraries/SmartStore.Services/Media/MediaExtensions.cs renamed to src/Libraries/SmartStore.Services/Media/MediaHelper.cs

File renamed without changes.

src/Libraries/SmartStore.Services/SmartStore.Services.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@
323323
<Compile Include="Media\Storage\DatabaseMediaStorageProvider.cs" />
324324
<Compile Include="Media\Storage\FileSystemMediaStorageProvider.cs" />
325325
<Compile Include="Media\Storage\IMediaStorageProvider.cs" />
326-
<Compile Include="Media\MediaExtensions.cs" />
326+
<Compile Include="Media\MediaHelper.cs" />
327327
<Compile Include="Media\Storage\IMediaMover.cs" />
328328
<Compile Include="Media\Storage\ISupportsMediaMoving.cs" />
329329
<Compile Include="Media\Storage\MediaMoverContext.cs" />

0 commit comments

Comments
 (0)