-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
170 additions
and
64 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,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Damselfly.Core.Interfaces; | ||
|
||
namespace Damselfly.Core.ImageProcessing | ||
{ | ||
public class ImageProcessorFactory | ||
{ | ||
private ImageMagickProcessor imProcessor; | ||
private SkiaSharpProcessor skiaProcessor; | ||
private ImageSharpProcessor isharpProcessor; | ||
private string rootContentPath; | ||
|
||
public void SetContentPath(string path) | ||
{ | ||
rootContentPath = path; | ||
} | ||
|
||
/// <summary> | ||
/// Takes a file extension, and returns an ImageProcessor that can generate | ||
/// thumbnails for that file type. | ||
/// </summary> | ||
/// <param name="fileExtension"></param> | ||
/// <returns></returns> | ||
public IImageProcessor GetProcessor( string fileExtension ) | ||
{ | ||
if( ! fileExtension.StartsWith( "." ) ) | ||
{ | ||
fileExtension = $".{fileExtension}"; | ||
} | ||
|
||
if( SkiaSharpProcessor.SupportedFileExtensions.Any( x => x.Equals( fileExtension, StringComparison.OrdinalIgnoreCase ) ) ) | ||
{ | ||
if (skiaProcessor == null) | ||
skiaProcessor = new SkiaSharpProcessor(); | ||
|
||
return skiaProcessor; | ||
} | ||
|
||
if (ImageSharpProcessor.SupportedFileExtensions.Any(x => x.Equals(fileExtension, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
if (isharpProcessor == null) | ||
{ | ||
isharpProcessor = new ImageSharpProcessor(); | ||
isharpProcessor.SetFontPath(Path.Combine(rootContentPath, "fonts")); | ||
} | ||
return isharpProcessor; | ||
} | ||
|
||
if (ImageMagickProcessor.SupportedFileExtensions.Any(x => x.Equals(fileExtension, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
if (imProcessor == null) | ||
imProcessor = new ImageMagickProcessor(); | ||
|
||
return imProcessor; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.