Skip to content

Commit

Permalink
Add tests for wide/tall image with Exif orientation.
Browse files Browse the repository at this point in the history
  • Loading branch information
coobird committed Sep 23, 2022
1 parent 17bf056 commit 26b53a1
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2327,10 +2327,10 @@ public void correctOrientationFromFile() throws IOException {
}

@Test
public void correctOrientationRectangleFromFile() throws IOException {
public void correctOrientationWideFromFile() throws IOException {
// given
File sourceFile = TestUtils.copyResourceToTemporaryFile(
String.format("Exif/sourceRect_%s.jpg", orientation),
String.format("Exif/sourceWide_%s.jpg", orientation),
temporaryFolder
);

Expand All @@ -2353,6 +2353,87 @@ public void correctOrientationRectangleFromFile() throws IOException {
assertEquals(40, result.getHeight());
}

@Test
public void correctOrientationTallFromFile() throws IOException {
// given
File sourceFile = TestUtils.copyResourceToTemporaryFile(
String.format("Exif/sourceTall_%s.jpg", orientation),
temporaryFolder
);

// when
BufferedImage result =
Thumbnails.of(sourceFile)
.size(40, 80)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(40, result.getWidth());
assertEquals(80, result.getHeight());
}

@Test
public void correctOrientationWideScaleFromFile() throws IOException {
// given
File sourceFile = TestUtils.copyResourceToTemporaryFile(
String.format("Exif/sourceWide_%s.jpg", orientation),
temporaryFolder
);

// when
BufferedImage result =
Thumbnails.of(sourceFile)
.scale(0.5)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(80, result.getWidth());
assertEquals(40, result.getHeight());
}

@Test
public void correctOrientationTallScaleFromFile() throws IOException {
// given
File sourceFile = TestUtils.copyResourceToTemporaryFile(
String.format("Exif/sourceTall_%s.jpg", orientation),
temporaryFolder
);

// when
BufferedImage result =
Thumbnails.of(sourceFile)
.scale(0.5)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(40, result.getWidth());
assertEquals(80, result.getHeight());
}

@Test
public void correctOrientationFromInputStream() throws Exception {
// given
Expand Down Expand Up @@ -2380,10 +2461,10 @@ public void correctOrientationFromInputStream() throws Exception {
}

@Test
public void correctOrientationRectangleFromInputStream() throws Exception {
public void correctOrientationWideFromInputStream() throws Exception {
// given
InputStream is = TestUtils.getResourceStream(
String.format("Exif/sourceRect_%s.jpg", orientation)
String.format("Exif/sourceWide_%s.jpg", orientation)
);

// when
Expand All @@ -2404,6 +2485,84 @@ public void correctOrientationRectangleFromInputStream() throws Exception {
assertEquals(80, result.getWidth());
assertEquals(40, result.getHeight());
}

@Test
public void correctOrientationTallFromInputStream() throws Exception {
// given
InputStream is = TestUtils.getResourceStream(
String.format("Exif/sourceTall_%s.jpg", orientation)
);

// when
BufferedImage result =
Thumbnails.of(is)
.size(40, 80)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(40, result.getWidth());
assertEquals(80, result.getHeight());
}

@Test
public void correctOrientationWideScaleFromInputStream() throws Exception {
// given
InputStream is = TestUtils.getResourceStream(
String.format("Exif/sourceWide_%s.jpg", orientation)
);

// when
BufferedImage result =
Thumbnails.of(is)
.scale(0.5)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(80, result.getWidth());
assertEquals(40, result.getHeight());
}

@Test
public void correctOrientationTallScaleFromInputStream() throws Exception {
// given
InputStream is = TestUtils.getResourceStream(
String.format("Exif/sourceTall_%s.jpg", orientation)
);

// when
BufferedImage result =
Thumbnails.of(is)
.scale(0.5)
.asBufferedImage();

// then
BufferedImageAssert.assertMatches(
result,
new float[] {
1, 1, 1,
1, 1, 1,
1, 0, 0,
}
);
assertEquals(40, result.getWidth());
assertEquals(80, result.getHeight());
}
}

@RunWith(Parameterized.class)
Expand Down
Binary file added src/test/resources/Exif/sourceTall_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/Exif/sourceTall_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 26b53a1

Please sign in to comment.