Browse Source

Fix focus point.

pull/544/head
Sebastian 6 years ago
parent
commit
3113e73e59
  1. 10
      backend/src/Squidex.Infrastructure/Assets/ImageSharp/ImageSharpAssetThumbnailGenerator.cs
  2. 2
      backend/src/Squidex.Infrastructure/Assets/ResizeOptions.cs
  3. 2
      backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
  4. 6
      backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs

10
backend/src/Squidex.Infrastructure/Assets/ImageSharp/ImageSharpAssetThumbnailGenerator.cs

@ -11,7 +11,6 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using ISResizeMode = SixLabors.ImageSharp.Processing.ResizeMode;
using ISResizeOptions = SixLabors.ImageSharp.Processing.ResizeOptions;
@ -39,7 +38,7 @@ namespace Squidex.Infrastructure.Assets.ImageSharp
{
var encoder = Configuration.Default.ImageFormatsManager.FindEncoder(format);
if (options.Quality.HasValue)
if (options.Quality.HasValue && (encoder is JpegEncoder || !options.KeepFormat))
{
encoder = new JpegEncoder { Quality = options.Quality.Value };
}
@ -72,11 +71,10 @@ namespace Squidex.Infrastructure.Assets.ImageSharp
if (options.FocusX.HasValue && options.FocusY.HasValue)
{
resizeOptions.CenterCoordinates = new float[]
{
resizeOptions.CenterCoordinates = new PointF(
+(options.FocusX.Value / 2f) + 0.5f,
-(options.FocusX.Value / 2f) + 0.5f
};
-(options.FocusY.Value / 2f) + 0.5f
);
}
sourceImage.Mutate(x => x.Resize(resizeOptions));

2
backend/src/Squidex.Infrastructure/Assets/ResizeOptions.cs

@ -23,6 +23,8 @@ namespace Squidex.Infrastructure.Assets
public float? FocusY { get; set; }
public bool KeepFormat { get; set; }
public bool IsValid
{
get { return Width > 0 || Height > 0 || Quality > 0; }

2
backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj

@ -31,7 +31,7 @@
<PackageReference Include="NJsonSchema" Version="10.1.18" />
<PackageReference Include="NodaTime" Version="3.0.0" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-rc0003" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />

6
backend/src/Squidex/Areas/Api/Controllers/Assets/Models/AssetContentQueryDto.cs

@ -75,6 +75,12 @@ namespace Squidex.Areas.Api.Controllers.Assets.Models
[FromQuery(Name = "nofocus")]
public bool IgnoreFocus { get; set; }
/// <summary>
/// True to not use JPEG encoding when quality is set and the image is not a JPEG. Default: false.
/// </summary>
[FromQuery(Name = "keepformat")]
public bool KeepFormat { get; set; }
/// <summary>
/// True to force a new resize even if it already stored.
/// </summary>

Loading…
Cancel
Save