Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions DotNetThumbor/DotNetThumbor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>DotNetThumbor.dll</PackageId>
<PackageVersion>1.2</PackageVersion>
<Authors>Mi9</Authors>
<PackageLicenseUrl>https://github.com/mi9/DotNetThumbor/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/mi9/DotNetThumbor</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Description>DotNet library for the Thumbor image service which allows you to build URIs using a fluent API.</Description>
<PackageTags>thumbor image resizer</PackageTags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<ExternalConsole>false</ExternalConsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>
</DebugType>
<DebugType></DebugType>
</PropertyGroup>
</Project>
</Project>
14 changes: 0 additions & 14 deletions DotNetThumbor/DotNetThumbor.dll.nuspec

This file was deleted.

39 changes: 29 additions & 10 deletions DotNetThumbor/ThumborImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ThumborImage
{
private readonly List<string> watermarks = new List<string>();

private readonly Dictionary<string, string> filters = new Dictionary<string, string>();
private readonly Dictionary<string, string> filters = new Dictionary<string, string>();

private readonly ThumborSigner thumborSigner;

Expand Down Expand Up @@ -145,15 +145,23 @@ public ThumborImage Grayscale(bool grayscaleImage)

/// <summary>
/// Adds a watermark image to this image. The watermark image can be the output of another thumbor image. See https://github.com/thumbor/thumbor/wiki/Watermark for details.
/// Can be called multiple times with each watermark being included on the base image. The last added watermark
/// Can be called multiple times with each watermark being included on the base image. The last added watermark
/// will overlay all previous watermarks if there is an overlap.
/// </summary>
/// <param name="watermarkImageUrl">URL to the image to use as a watermark. Can be the output of another thumbor image.</param>
/// <param name="right">How many pixels right the watermark should be.</param>
/// <param name="down">How many pixels down the watermark should be.</param>
/// <param name="right">
/// How many pixels right the watermark should be. If the value is 'center' (without the single quotes), the watermark will be centered horizontally.
/// If the value is 'repeat' (without the single quotes), the watermark will be repeated horizontally.
/// If the value is a positive or negative number followed by a 'p' (ex. 20p), it will calculate the value from the image width as percentage.
/// </param>
/// <param name="down">
/// How many pixels down the watermark should be. If the value is 'center' (without the single quotes), the watermark will be centered vertically.
/// If the value is 'repeat' (without the single quotes), the watermark will be repeated vertically.
/// If the value is a positive or negative number followed by a 'p' (ex. 20p), it will calculate the value from the image height as percentage.
/// </param>
/// <param name="transparency">Watermark image transparency 0 = opaque - 100 fully transparent</param>
/// <returns>The current thumbor image object.</returns>
public ThumborImage Watermark(string watermarkImageUrl, int right, int down, int transparency)
public ThumborImage Watermark(string watermarkImageUrl, string right, string down, int transparency)
{
this.watermarks.Add(string.Format("watermark({0},{1},{2},{3})", watermarkImageUrl, right, down, transparency));
return this;
Expand Down Expand Up @@ -513,15 +521,26 @@ public ThumborImage Curve(IList<Tuple<int, int>> curveAll, IList<Tuple<int, int>
{
var curve = string.Format(
"[{0}],[{1}],[{2}],[{3}]",
string.Join(",", curveAll.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveRed.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveGreen.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveBlue.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))));
string.Join(",", curveAll.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveRed.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveGreen.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))),
string.Join(",", curveBlue.Select(x => string.Format("({0},{1})", x.Item1, x.Item2))));

this.ReplaceOrAddFilter("curve", curve);
return this;
}

/// <summary>
/// Sets the background layer to the specified color. See https://thumbor.readthedocs.io/en/latest/background_color.html for details.
/// </summary>
/// <param name="color">The color name (like in HTML) or hexadecimal rgb expression without the “#” character (see https://en.wikipedia.org/wiki/Web_colors for example).</param>
/// <returns>The current thumbor image object.</returns>
public ThumborImage BackgroundColor(string color)
{
this.ReplaceOrAddFilter("background_color", color);
return this;
}

/// <summary>
/// An alias to ToUrl
/// </summary>
Expand Down Expand Up @@ -586,7 +605,7 @@ private string FormatUrlParts()
{
urlParts.Add(this.trim == Thumbor.ImageTrimOption.BottomRight ? "trim:bottom-right" : "trim");
}

if (!string.IsNullOrEmpty(this.cropCoordinates))
{
urlParts.Add(this.cropCoordinates);
Expand Down
2 changes: 2 additions & 0 deletions DotNetThumborTest/DotNetThumborTest.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -124,6 +125,7 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
15 changes: 9 additions & 6 deletions DotNetThumborTest/TestThumborFilters/TestWatermark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
public class TestWatermark
{
[Test]
[TestCase("http://image.url", 1, 2, 3)]
[TestCase("http://localhost/image.jpg", 99, 23, 42)]
public void ThumborWatermark(string imageUrl, int right, int down, int transparency)
[TestCase("http://image.url", "1", "2", 3)]
[TestCase("http://localhost/image.jpg", "99", "23", 42)]
[TestCase("http://localhost/image.jpg", "center", "center", 42)]
[TestCase("http://localhost/image.jpg", "repeat", "repeat", 42)]
[TestCase("http://localhost/image.jpg", "20p", "20p", 42)]
public void ThumborWatermark(string imageUrl, string right, string down, int transparency)
{
var thumbor = new Thumbor("http://localhost/");
var resizedUrl = thumbor.BuildImage("http://localhost/image.jpg")
Expand All @@ -26,8 +29,8 @@ public void ThumborWatermarks()
{
var thumbor = new Thumbor("http://localhost/");
var resizedUrl = thumbor.BuildImage("http://localhost/image.jpg")
.Watermark("http://image1.url", 1, 3, 5)
.Watermark("http://image2.url", 2, 4, 6)
.Watermark("http://image1.url", "1", "3", 5)
.Watermark("http://image2.url", "2", "4", 6)
.ToFullUrl();
resizedUrl.Should().Be("http://localhost/unsafe/filters:watermark(http://image1.url,1,3,5):watermark(http://image2.url,2,4,6)/http://localhost/image.jpg");
}
Expand All @@ -40,7 +43,7 @@ public void ThumborWatermarkUsingThumbor()
var watermark = thumbor.BuildImage("http://localhost/watermark.png").ToFullUrl();

var resizedUrl = thumbor.BuildImage("http://localhost/image.jpg")
.Watermark(watermark, 0, 0, 50)
.Watermark(watermark, "0", "0", 50)
.ToFullUrl();
resizedUrl.Should().Be("http://localhost/unsafe/filters:watermark(http://localhost/unsafe/http://localhost/watermark.png,0,0,50)/http://localhost/image.jpg");
}
Expand Down
4 changes: 2 additions & 2 deletions DotNetThumborTest/TestThumborImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public void ThumborMultiTest()
.Saturation(1.7)
.Sharpen(5.0, 1.2, true)
.StripIcc(true)
.Watermark(watermark, 0, 10, 50)
.Watermark(watermark, "0", "10", 50)
.ToFullUrl();
// Verified as a value URL when used against internal thumbor server
resizedUrl.Should().Be("http://localhost/unsafe/trim/fit-in/200x400/left/bottom/smart/filters:blur(1,2):brightness(50):colorize(1,2,3,AAAAAA):contrast(50):convolution(1;2;1,3,false):curve([(1,2)],[(3,4)],[(5,6)],[(7,8)]):equalize():extract_focal():fill(blue):format(webp):gifv(webm):grayscale():max_bytes(100000):noise(50):no_upscale():quality(100):rgb(1,2,3):rotate(90):round_corners(10|20,1,2,3):saturation(1.7):sharpen(5,1.2,true):strip_icc():watermark(http://localhost/unsafe/-0x-0/https://localhost/watermark.png,0,10,50)/https://localhost/image.jpg");
Expand All @@ -453,7 +453,7 @@ public void ThumborNonFluentTest()
resizedUrlImage.Grayscale(true);
resizedUrlImage.Fill("blue");
resizedUrlImage.Quality(100);
resizedUrlImage.Watermark(watermark, 0, 10, 50);
resizedUrlImage.Watermark(watermark, "0", "10", 50);
resizedUrlImage.Smart(true);
resizedUrlImage.FitIn(true);
resizedUrlImage.HorizontalAlign(Thumbor.ImageHorizontalAlign.Left);
Expand Down
1 change: 1 addition & 0 deletions DotNetThumborTest/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<packages>
<package id="FluentAssertions" version="5.4.2" targetFramework="net461" />
<package id="NUnit" version="3.11.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.17.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>