Skip to content

Commit e83c10c

Browse files
committed
Only create rectangle when mode = manual
1 parent 603f3e5 commit e83c10c

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/ImageSharp.Web/Processors/ResizeWebProcessor.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ public class ResizeWebProcessor : IImageWebProcessor
6262
/// </summary>
6363
public const string Compand = "compand";
6464

65-
/// <summary>
66-
/// The command constant for the resize TargetRectangle X
67-
/// </summary>
68-
public const string TargetRectangleWidth = "targetrectanglewidth";
69-
70-
/// <summary>
71-
/// The command constant for the resize TargetRectangle X
72-
/// </summary>
73-
public const string TargetRectangleHeight = "targetrectangleheight";
74-
7565
private static readonly IEnumerable<string> ResizeCommands
7666
= new[]
7767
{
@@ -137,18 +127,18 @@ internal static ResizeOptions GetResizeOptions(
137127
return null;
138128
}
139129

140-
Rectangle? targetRectangle = ParseRectangle(commands, parser, culture);
130+
ResizeMode mode = GetMode(commands, parser, culture);
141131

142132
return new()
143133
{
144134
Size = size,
145135
CenterCoordinates = GetCenter(orientation, commands, parser, culture),
146136
Position = GetAnchor(orientation, commands, parser, culture),
147-
Mode = GetMode(commands, parser, culture),
137+
Mode = mode,
148138
Compand = GetCompandMode(commands, parser, culture),
149139
Sampler = GetSampler(commands),
150140
PadColor = parser.ParseValue<Color>(commands.GetValueOrDefault(Color), culture),
151-
TargetRectangle = targetRectangle
141+
TargetRectangle = mode is ResizeMode.Manual ? new Rectangle(0, 0, size.Width, size.Height) : null
152142
};
153143
}
154144

@@ -172,23 +162,6 @@ private static Size ParseSize(
172162
return ExifOrientationUtilities.Transform(new Size(width, height), orientation);
173163
}
174164

175-
private static Rectangle? ParseRectangle(
176-
CommandCollection commands,
177-
CommandParser parser,
178-
CultureInfo culture)
179-
{
180-
if (!commands.Contains(TargetRectangleWidth) || !commands.Contains(TargetRectangleHeight))
181-
{
182-
return null;
183-
}
184-
185-
// The command parser will reject negative numbers as it clamps values to ranges.
186-
int width = (int)parser.ParseValue<uint>(commands.GetValueOrDefault(TargetRectangleWidth), culture);
187-
int height = (int)parser.ParseValue<uint>(commands.GetValueOrDefault(TargetRectangleHeight), culture);
188-
189-
return new Rectangle(0, 0, width, height);
190-
}
191-
192165
private static PointF? GetCenter(
193166
ushort orientation,
194167
CommandCollection commands,

0 commit comments

Comments
 (0)