-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
manually merging new media detectors
- Loading branch information
Showing
7 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
|
||
namespace Umbraco.Web.Media.Exif | ||
{ | ||
internal class SvgFile : ImageFile | ||
{ | ||
public SvgFile(Stream fileStream) | ||
{ | ||
fileStream.Position = 0; | ||
|
||
var document = XDocument.Load(fileStream); //if it throws an exception the ugly try catch in MediaFileSystem will catch it | ||
|
||
var width = document.Root?.Attributes().Where(x => x.Name == "width").Select(x => x.Value).FirstOrDefault(); | ||
var height = document.Root?.Attributes().Where(x => x.Name == "height").Select(x => x.Value).FirstOrDefault(); | ||
|
||
Properties.Add(new ExifSInt(ExifTag.PixelYDimension, | ||
height == null ? Core.Constants.Conventions.Media.DefaultSize : int.Parse(height))); | ||
Properties.Add(new ExifSInt(ExifTag.PixelXDimension, | ||
width == null ? Core.Constants.Conventions.Media.DefaultSize : int.Parse(width))); | ||
|
||
Format = ImageFileFormat.SVG; | ||
} | ||
|
||
public override void Save(Stream stream) | ||
{ | ||
} | ||
|
||
public override Image ToImage() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.IO; | ||
|
||
namespace Umbraco.Web.Media.TypeDetector | ||
{ | ||
public class JpegDetector : RasterizedTypeDetector | ||
{ | ||
public static bool IsOfType(Stream fileStream) | ||
{ | ||
var header = GetFileHeader(fileStream); | ||
|
||
return header[0] == 0xff && header[1] == 0xD8; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Web/Media/TypeDetector/RasterizedTypeDetector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.IO; | ||
|
||
namespace Umbraco.Web.Media.TypeDetector | ||
{ | ||
public abstract class RasterizedTypeDetector | ||
{ | ||
public static byte[] GetFileHeader(Stream fileStream) | ||
{ | ||
fileStream.Seek(0, SeekOrigin.Begin); | ||
byte[] header = new byte[8]; | ||
fileStream.Seek(0, SeekOrigin.Begin); | ||
|
||
return header; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.IO; | ||
using System.Xml.Linq; | ||
|
||
namespace Umbraco.Web.Media.TypeDetector | ||
{ | ||
public class SvgDetector | ||
{ | ||
public static bool IsOfType(Stream fileStream) | ||
{ | ||
var document = new XDocument(); | ||
|
||
try | ||
{ | ||
document = XDocument.Load(fileStream); | ||
} | ||
catch (System.Exception ex) | ||
{ | ||
return false; | ||
} | ||
|
||
return document.Root?.Name.LocalName == "svg"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace Umbraco.Web.Media.TypeDetector | ||
{ | ||
public class TIFFDetector | ||
{ | ||
public static bool IsOfType(Stream fileStream) | ||
{ | ||
string tiffHeader = GetFileHeader(fileStream); | ||
|
||
return tiffHeader == "MM\x00\x2a" || tiffHeader == "II\x2a\x00"; | ||
} | ||
|
||
public static string GetFileHeader(Stream fileStream) | ||
{ | ||
var header = RasterizedTypeDetector.GetFileHeader(fileStream); | ||
|
||
string tiffHeader = Encoding.ASCII.GetString(header, 0, 4); | ||
|
||
return tiffHeader; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters