Skip to content

Commit

Permalink
Add S3 sample (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Sep 9, 2020
1 parent 1d497d6 commit 4ef69db
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 125 deletions.
2 changes: 1 addition & 1 deletion samples/NetVips.Samples/ISample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public interface ISample

string Category { get; }

string Execute(string[] args);
void Execute(string[] args);
}
}
4 changes: 4 additions & 0 deletions samples/NetVips.Samples/NetVips.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.5.0.9" />
</ItemGroup>

</Project>
18 changes: 8 additions & 10 deletions samples/NetVips.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ static void Main(string[] args)
input = Console.ReadLine();
}

if (int.TryParse(input, out var userChoice) && TryGetSample(userChoice, out var sample))
if (int.TryParse(input, out var userChoice))
{
Console.WriteLine($"Executing sample: {sample.Name}");
var result = sample.Execute(sampleArgs);
Console.WriteLine("Sample successfully executed!");
if (result != null)
if (!TryGetSample(userChoice, out var sample))
{
Console.WriteLine($"Result: {result}");
Console.WriteLine("Sample doesn't exists, try again");
continue;
}
}
else
{
Console.WriteLine("Sample doesn't exists, try again");

Console.WriteLine($"Executing sample: {sample.Name}");
sample.Execute(sampleArgs);
Console.WriteLine("Sample successfully executed!");
}

// Clear any arguments
Expand Down
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/Canny.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace NetVips.Samples
{
using System;

public class Canny : ISample
{
public string Name => "Canny";
public string Category => "Edge detection";

public const string Filename = "images/lichtenstein.jpg";

public string Execute(string[] args)
public void Execute(string[] args)
{
var im = Image.NewFromFile(Filename, access: Enums.Access.Sequential);

Expand All @@ -22,7 +24,7 @@ public string Execute(string[] args)

im.WriteToFile("canny.jpg");

return "See canny.jpg";
Console.WriteLine("See canny.jpg");
}
}
}
4 changes: 2 additions & 2 deletions samples/NetVips.Samples/Samples/CaptchaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Image Wobble(Image image)
return image.Mapim(xy);
}

public string Execute(string[] args)
public void Execute(string[] args)
{
var random = new Random();

Expand Down Expand Up @@ -98,7 +98,7 @@ public string Execute(string[] args)

final.WriteToFile("captcha.jpg");

return "See captcha.jpg";
Console.WriteLine("See captcha.jpg");
}
}
}
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/Combine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NetVips.Samples
{
using System;

/// <summary>
/// From: https://github.com/libvips/lua-vips/blob/master/example/combine.lua
/// </summary>
Expand All @@ -14,7 +16,7 @@ public class Combine : ISample
public const int Left = 100;
public const int Top = 100;

public string Execute(string[] args)
public void Execute(string[] args)
{
var main = Image.NewFromFile(MainFilename, access: Enums.Access.Sequential);
var watermark = Image.NewFromFile(WatermarkFilename, access: Enums.Access.Sequential);
Expand All @@ -37,7 +39,7 @@ public string Execute(string[] args)

combined.WriteToFile("combine.jpg");

return "See combine.jpg";
Console.WriteLine("See combine.jpg");
}
}
}
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/Duotone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NetVips.Samples
{
using System;

/// <summary>
/// From: https://github.com/lovell/sharp/issues/1235#issuecomment-390907151
/// </summary>
Expand All @@ -16,7 +18,7 @@ public class Duotone : ISample
// #D8E74F as CIELAB triple
public double[] Stop = { 88.12, -23.952, 69.178 };

public string Execute(string[] args)
public void Execute(string[] args)
{
// Makes a lut which is a smooth gradient from start colour to stop colour,
// with start and stop in CIELAB
Expand Down Expand Up @@ -48,7 +50,7 @@ public string Execute(string[] args)
// Finally, write the result back to a file on disk
im.WriteToFile("duotone.jpg");

return "See duotone.jpg";
Console.WriteLine("See duotone.jpg");
}
}
}
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/EmbedMultiplyConv.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NetVips.Samples
{
using System;

/// <summary>
/// From: https://github.com/libvips/ruby-vips#example
/// </summary>
Expand All @@ -10,7 +12,7 @@ public class EmbedMultiplyConv : ISample

public const string Filename = "images/lichtenstein.jpg";

public string Execute(string[] args)
public void Execute(string[] args)
{
var im = Image.NewFromFile(Filename);

Expand All @@ -35,7 +37,7 @@ public string Execute(string[] args)
// finally, write the result back to a file on disk
im.WriteToFile("embed-multiply-conv.jpg");

return "See embed-multiply-conv.jpg";
Console.WriteLine("See embed-multiply-conv.jpg");
}
}
}
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/Emboss.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace NetVips.Samples
{
using System;

public class Emboss : ISample
{
public string Name => "Emboss";
public string Category => "Filter";

public const string Filename = "images/lichtenstein.jpg";

public string Execute(string[] args)
public void Execute(string[] args)
{
var im = Image.NewFromFile(Filename);

Expand Down Expand Up @@ -42,7 +44,7 @@ public string Execute(string[] args)

Image.Arrayjoin(images, across: 2).WriteToFile("emboss.jpg");

return "See emboss.jpg";
Console.WriteLine("See emboss.jpg");
}
}
}
5 changes: 3 additions & 2 deletions samples/NetVips.Samples/Samples/GdiConvert.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NetVips.Samples
{
using System;
using Extensions;
using System.Drawing.Imaging;

Expand All @@ -10,7 +11,7 @@ public class GdiConvert : ISample

public const string Filename = "images/PNG_transparency_demonstration_1.png";

public string Execute(string[] args)
public void Execute(string[] args)
{
var bitmap = new System.Drawing.Bitmap(Filename);

Expand Down Expand Up @@ -61,7 +62,7 @@ public string Execute(string[] args)
var image2 = bitmap.ToVips();
image2.WriteToFile("gdi-to-vips2.png");*/

return "See gdi-to-vips.png";
Console.WriteLine("See gdi-to-vips.png");
}
}
}
7 changes: 4 additions & 3 deletions samples/NetVips.Samples/Samples/GenerateEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ private string Generate()
return stringBuilder.ToString();
}

public string Execute(string[] args)
public void Execute(string[] args)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "This example can only be run on Windows";
Console.Error.WriteLine("This example can only be run on Windows");
return;
}

File.WriteAllText("Enums.Generated.cs", Generate());

return "See Enums.Generated.cs";
Console.WriteLine("See Enums.Generated.cs");
}
}
}
4 changes: 2 additions & 2 deletions samples/NetVips.Samples/Samples/GenerateImageClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ private string Generate(string indent = " ")
return stringBuilder.ToString();
}

public string Execute(string[] args)
public void Execute(string[] args)
{
File.WriteAllText("Image.Generated.cs", Generate());

return "See Image.Generated.cs";
Console.WriteLine("See Image.Generated.cs");
}
}
}
4 changes: 2 additions & 2 deletions samples/NetVips.Samples/Samples/GenerateImageOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ public string GenerateOperators()
return stringBuilder.ToString();
}

public string Execute(string[] args)
public void Execute(string[] args)
{
File.WriteAllText("Image.Operators.cs", GenerateOperators());
return "See Image.Operators.cs";
Console.WriteLine("See Image.Operators.cs");
}
}
}
6 changes: 4 additions & 2 deletions samples/NetVips.Samples/Samples/HelloWorld.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NetVips.Samples
{
using System;

/// <summary>
/// From: https://github.com/libvips/lua-vips/blob/master/example/hello-world.lua
/// </summary>
Expand All @@ -8,12 +10,12 @@ public class HelloWorld : ISample
public string Name => "Hello world";
public string Category => "Create";

public string Execute(string[] args)
public void Execute(string[] args)
{
var image = Image.Text("Hello <i>World!</i>", dpi: 300);
image.WriteToFile("hello-world.png");

return "See hello-world.png";
Console.WriteLine("See hello-world.png");
}
}
}
4 changes: 1 addition & 3 deletions samples/NetVips.Samples/Samples/IdentifyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public string GetExtensionNonTruncated(byte[] buffer)
}
}

public string Execute(string[] args)
public void Execute(string[] args)
{
Console.WriteLine("FindLoadBuffer function (non-truncated buffer)");
Console.WriteLine(GetExtension(File.ReadAllBytes("images/lichtenstein.jpg")));
Expand All @@ -76,8 +76,6 @@ public string Execute(string[] args)

Console.WriteLine("vips-loader function (truncated buffer)");
Console.WriteLine(GetExtensionNonTruncated(Encoding.UTF8.GetBytes("GIF89a")));

return "All done!";
}
}
}
14 changes: 6 additions & 8 deletions samples/NetVips.Samples/Samples/ImagePyramid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ImagePyramid : ISample
public const int TileSize = 50;
public const string Filename = "images/sample2.v";

public string Execute(string[] args)
public void Execute(string[] args)
{
// Build test image
var im = Image.NewFromFile(Filename, access: Enums.Access.Sequential);
Expand All @@ -20,26 +20,24 @@ public string Execute(string[] args)
var cts = new CancellationTokenSource();
cts.CancelAfter(5000);

var progress = new Progress<int>(percent =>
{
Console.Write($"\r{percent}% complete");
});
var progress = new Progress<int>(percent => Console.Write($"\r{percent}% complete"));
// Uncomment to kill the image after 5 sec
im.SetProgress(progress/*, cts.Token*/);
im.SetProgress(progress /*, cts.Token*/);

try
{
// Save image pyramid
im.Dzsave("images/image-pyramid");
}
catch (VipsException exception) {
catch (VipsException exception)
{
// Catch and log the VipsException,
// because we may block the evaluation of this image
Console.WriteLine("\n" + exception.Message);
}

Console.WriteLine();
return "See images/image-pyramid.dzi";
Console.WriteLine("See images/image-pyramid.dzi");
}
}
}
4 changes: 1 addition & 3 deletions samples/NetVips.Samples/Samples/LeakTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class LeakTest : ISample
/// </summary>
/// <param name="args">Command-line arguments.</param>
/// <returns>Result.</returns>
public string Execute(string[] args)
public void Execute(string[] args)
{
NetVips.LeakSet(true);

Expand All @@ -60,8 +60,6 @@ public string Execute(string[] args)
// uncomment this line together with the `NObjects` variable in GObject
// Console.WriteLine($"{GObject.NObjects} vips objects known to net-vips");
}

return "All done!";
}
}
}
Loading

0 comments on commit 4ef69db

Please sign in to comment.