Skip to content

Commit

Permalink
Merge branch 'gitanuj-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Feb 19, 2015
2 parents 9fb091b + 3e11b0d commit b96aea0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/com/squareup/pollexor/ThumborUrlBuilder.java
Expand Up @@ -36,6 +36,8 @@ public final class ThumborUrlBuilder {
private static final String FILTER_GRAYSCALE = "grayscale";
private static final String FILTER_EQUALIZE = "equalize";
private static final String FILTER_BLUR = "blur";
private static final String FILTER_NO_UPSCALE = "no_upscale";
private static final String FILTER_ROTATE = "rotate";

/** Original size for image width or height. **/
public static final int ORIGINAL_SIZE = Integer.MIN_VALUE;
Expand Down Expand Up @@ -788,5 +790,23 @@ public static String blur(int radius, int sigma) {
throw new IllegalArgumentException("Sigma must be greater than zero.");
}
return FILTER_BLUR + "(" + radius + "," + sigma + ")";
}
}

/** This filter tells thumbor not to upscale your images. */
public static String noUpscale() {
return FILTER_NO_UPSCALE + "()";
}

/**
* This filter rotates the given image according to the angle passed.
* @param angle The angle of rotation. Values can be either 0°, 90°, 180° or 270° – multiples of
* 90°. Angles equal to or greater than 360° will be replaced by their coterminal
* angle of rotation.
*/
public static String rotate(int angle) {
if (angle % 90 != 0) {
throw new IllegalArgumentException("Angle must be multiple of 90°");
}
return FILTER_ROTATE + "(" + angle + ")";
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/squareup/pollexor/ThumborUrlBuilderTest.java
Expand Up @@ -18,6 +18,8 @@
import static com.squareup.pollexor.ThumborUrlBuilder.sharpen;
import static com.squareup.pollexor.ThumborUrlBuilder.watermark;
import static com.squareup.pollexor.ThumborUrlBuilder.blur;
import static com.squareup.pollexor.ThumborUrlBuilder.noUpscale;
import static com.squareup.pollexor.ThumborUrlBuilder.rotate;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.fail;

Expand Down Expand Up @@ -507,4 +509,12 @@ public class ThumborUrlBuilderTest {
assertThat(blur(1,0)).isEqualTo("blur(1,0)");
assertThat(blur(1,1)).isEqualTo("blur(1,1)");
}

@Test public void testFilterNoUpscale() {
assertThat(noUpscale()).isEqualTo("no_upscale()");
}

@Test public void testFilterRotate() {
assertThat(rotate(90)).isEqualTo("rotate(90)");
}
}

0 comments on commit b96aea0

Please sign in to comment.