Skip to content

Instantly share code, notes, and snippets.

@giansalex
Created November 22, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giansalex/7f0b3a735ba8cdcc988cd5b25f5df364 to your computer and use it in GitHub Desktop.
Save giansalex/7f0b3a735ba8cdcc988cd5b25f5df364 to your computer and use it in GitHub Desktop.
Magick .Net - Optimize on the fly
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!");
}
}
}
}
}
<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