Skip to content

Commit b314ec9

Browse files
committed
add resize_to_fill operation
resolves #1
1 parent 4e2549a commit b314ec9

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

blitline-image-client/src/main/java/com/blitline/image/Blitline.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.blitline.image.functions.Rectangle;
3737
import com.blitline.image.functions.Resample;
3838
import com.blitline.image.functions.Resize;
39+
import com.blitline.image.functions.ResizeToFill;
3940
import com.blitline.image.functions.ResizeToFit;
4041
import com.blitline.image.functions.Rotate;
4142
import com.blitline.image.functions.RunExecutable;
@@ -51,12 +52,12 @@
5152
import com.blitline.image.functions.Watermark;
5253

5354
public class Blitline {
54-
55+
5556
/**
5657
* The API version this library will invoke. 1.20 fixed error reporting.
5758
*/
5859
public static final String BLITLINE_API_VERSION = "1.20";
59-
60+
6061
private Blitline() {
6162
}
6263

@@ -162,7 +163,7 @@ public static Ellipse drawEllipse(int centerX, int centerY, int width, int heigh
162163

163164
/**
164165
* Invokes ImageMagick's {@code -enhance} option; most applications will prefer {@link #autoEnhance()}.
165-
*
166+
*
166167
* @return the singleton instance of the {@link Enhance} function
167168
*/
168169
public static Enhance enhance() {
@@ -245,6 +246,10 @@ public static Resize resizeTo(int width, int height) {
245246
return new Resize(width, height);
246247
}
247248

249+
public static ResizeToFill resizeToFill(int width, int maxHeight) {
250+
return new ResizeToFill(width, maxHeight);
251+
}
252+
248253
public static ResizeToFit resizeToFit(int maxWidth, int maxHeight) {
249254
return new ResizeToFit(maxWidth, maxHeight);
250255
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.blitline.image.functions;
2+
3+
import com.blitline.image.functions.params.Gravity;
4+
5+
public class ResizeToFill extends AbstractFunction {
6+
7+
private static final long serialVersionUID = 1L;
8+
9+
@Override
10+
public String getName() {
11+
return "resize_to_fill";
12+
}
13+
14+
/**
15+
* Specify the maximum dimensions of the resized image. You may specify zero for one of the dimensions to leave it
16+
* unconstrained.
17+
*
18+
* @param width
19+
* the maximum width of the resulting image, or zero for any width
20+
* @param maxHeight
21+
* the maximum height of the resulting image, or zero for any height
22+
*/
23+
public ResizeToFill(int width, int maxHeight) {
24+
if (width == 0)
25+
throw new IllegalArgumentException("width must be specified");
26+
27+
params.put("width", width);
28+
29+
if (maxHeight > 0)
30+
params.put("height", maxHeight);
31+
}
32+
33+
/**
34+
* Do not upscale the image if the original is already smaller than the maximum dimensions. Sets the {@code only_shrink_larger}
35+
* JSON option.
36+
*
37+
* @return {@literal this}
38+
*/
39+
public ResizeToFill doNotUpscale() {
40+
params.put("only_shrink_larger", Boolean.TRUE);
41+
return this;
42+
}
43+
44+
public ResizeToFill gravity(Gravity gravity) {
45+
params.put("gravity", gravity);
46+
return this;
47+
}
48+
}

0 commit comments

Comments
 (0)