Created
November 22, 2017 21:08
-
-
Save giansalex/7f0b3a735ba8cdcc988cd5b25f5df364 to your computer and use it in GitHub Desktop.
Magick .Net - Optimize on the fly
This file contains hidden or 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
using System; | |
using ImageMagick; | |
using System.IO; | |
namespace coreImagick | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var bytes = File.ReadAllBytes(@"path\image.jpg"); | |
using (var mem = new MemoryStream(bytes)) | |
{ | |
var opt = new ImageOptimizer(); | |
if (opt.IsSupported(mem)) | |
{ | |
var res = opt.Compress(mem); | |
Console.WriteLine("Resultado Optimizacion: " + res); | |
var result = mem.ToArray(); | |
File.WriteAllBytes("image.jpg", mem.ToArray()); | |
} | |
else | |
{ | |
Console.WriteLine("No soportado!"); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.0</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Magick.NET-Q16-x64" Version="7.1.0" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment