com.google.appengine.api.images.ImagesService.OutputEncoding Java Examples

The following examples show how to use com.google.appengine.api.images.ImagesService.OutputEncoding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageUtil.java    From wmf2svg with Apache License 2.0 6 votes vote down vote up
public byte[] convert(byte[] image, String destType, boolean reverse) {
	if (destType == null) {
		throw new IllegalArgumentException("dest type is null.");
	} else {
		destType = destType.toLowerCase();
	}

	ImagesService.OutputEncoding encoding = null;
	if ("png".equals(destType)) {
		encoding = OutputEncoding.PNG;
	} else if ("jpeg".equals(destType)) {
		encoding = OutputEncoding.JPEG;
	} else {
		throw new UnsupportedOperationException("unsupported image encoding: " + destType);
	}

	ImagesService imagesService = ImagesServiceFactory.getImagesService();
	Image bmp = ImagesServiceFactory.makeImage(image);

	Transform t = (reverse) ? ImagesServiceFactory.makeVerticalFlip() : ImagesServiceFactory.makeCompositeTransform();
	return imagesService.applyTransform(t, bmp, encoding).getImageData();
}
 
Example #2
Source File: TransformationsTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeAsync() throws IOException {
    InputSettings inputSettings = new InputSettings();
    OutputSettings outputSettings = new OutputSettings(OutputEncoding.PNG);

    Image originalImage = readImage(CAPEDWARF_PNG);
    Image resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(400, 286), originalImage));
    assertEquals(400, resizedImage.getWidth());
    assertEquals(286, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, outputSettings));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, inputSettings, outputSettings));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, OutputEncoding.JPEG));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());
}
 
Example #3
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@Test
public void testRotate() throws IOException {
    ChkType chkType;
    for (int dg : DEGREES) {
        Transform transform = ImagesServiceFactory.makeRotate(dg);
        if ((dg == 90) || (dg == 270)) {
            chkType = ChkType.ROTATE;
        } else {
            chkType = ChkType.FLIP;
        }
        for (String sfile : FNAMES) {
            for (OutputEncoding encoding : ENCODES) {
                applyAndVerify(sfile, transform, chkType, encoding);
            }
        }
    }
}
 
Example #4
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
private void applyAndVerify(String fname, Transform transform, ChkType chkType, OutputEncoding outType) throws IOException {
    int expectedWidth = -1;
    int expectedHeight = -1;

    Image image = readImage(fname);
    if (chkType == ChkType.FLIP) {
        expectedWidth = image.getWidth();
        expectedHeight = image.getHeight();
    } else if (chkType == ChkType.ROTATE) {
        expectedWidth = image.getHeight();
        expectedHeight = image.getWidth();
    } else if (chkType == ChkType.CROP) {
        expectedWidth = image.getWidth() / 2;
        expectedHeight = image.getHeight() / 2;
    }
    Image transImg = imagesService.applyTransform(transform, image, outType);
    assertEquals(expectedWidth, transImg.getWidth());
    assertEquals(expectedHeight, transImg.getHeight());
}
 
Example #5
Source File: TifImageTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void assertTransformation(Transform transform, String transformType) throws IOException {
    String expectedImage = "beach" + transformType + ".";
    for (OutputEncoding outType : OUTPUT_ENCODE) {
        String expectImageFile = expectedImage + outType.toString().toLowerCase();
        Image expected = readImage(expectImageFile);
        Image image = readImage(BEACH_TIF);
        Image transImg = imagesService.applyTransform(transform, image, outType);

        assertImages(transform, expected, transImg);
    }
}
 
Example #6
Source File: CompositeTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncoding() throws IOException {
    Image originalImage = readImage(CAPEDWARF_PNG);
    Composite c1 = ImagesServiceFactory.makeComposite(originalImage, 0, 0, 1, Composite.Anchor.BOTTOM_LEFT);
    Image ci = imagesService.composite(newArrayList(c1), 200, 143, 0, OutputEncoding.JPEG);
    assertImages(null, originalImage, ci);
}
 
Example #7
Source File: CompositeTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testSettings() throws IOException {
    Image originalImage = readImage(CAPEDWARF_PNG);
    Composite c1 = ImagesServiceFactory.makeComposite(originalImage, 0, 0, 1, Composite.Anchor.BOTTOM_LEFT);
    Image ci = imagesService.composite(newArrayList(c1), 200, 143, 0, new OutputSettings(OutputEncoding.JPEG));
    assertImages(null, originalImage, ci);
}
 
Example #8
Source File: TransformationsTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testResize() throws IOException {
    InputSettings inputSettings = new InputSettings();
    OutputSettings outputSettings = new OutputSettings(OutputEncoding.PNG);

    Image originalImage = readImage(CAPEDWARF_PNG);
    assertEquals(200, originalImage.getWidth());
    assertEquals(143, originalImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    Image resizedImage = imagesService.applyTransform(ImagesServiceFactory.makeResize(400, 286), originalImage);
    assertEquals(400, resizedImage.getWidth());
    assertEquals(286, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(400, 286), originalImage));
    assertEquals(400, resizedImage.getWidth());
    assertEquals(286, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = imagesService.applyTransform(ImagesServiceFactory.makeResize(300, 286), originalImage, inputSettings, outputSettings);
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = waitOnFuture(imagesService.applyTransformAsync(ImagesServiceFactory.makeResize(300, 286), originalImage, inputSettings, outputSettings));
    assertEquals(300, resizedImage.getWidth());
    assertEquals(215, resizedImage.getHeight());

    originalImage = readImage(CAPEDWARF_PNG);
    resizedImage = imagesService.applyTransform(ImagesServiceFactory.makeResize(400, 200), originalImage, outputSettings);
    assertEquals(280, resizedImage.getWidth());
    assertEquals(200, resizedImage.getHeight());
}
 
Example #9
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeelLucky() throws IOException {
    // I'm Feeling Lucky is not available in dev_appserver, CapeDwarf
    assumeEnvironment(Environment.APPSPOT);

    Transform transform = ImagesServiceFactory.makeImFeelingLucky();
    for (String sfile : FNAMES) {
        for (OutputEncoding encoding : ENCODES) {
            applyAndVerify(sfile, transform, ChkType.FLIP, encoding);
        }
    }
}
 
Example #10
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testHorizontalFlip() throws IOException {
    ChkType chkType = ChkType.FLIP;
    Transform transform = ImagesServiceFactory.makeHorizontalFlip();
    for (String sfile : FNAMES) {
        for (OutputEncoding encoding : ENCODES) {
            applyAndVerify(sfile, transform, chkType, encoding);
        }
    }
}
 
Example #11
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testVerticalFlip() throws IOException {
    ChkType chkType = ChkType.FLIP;
    Transform transform = ImagesServiceFactory.makeVerticalFlip();
    for (String sfile : FNAMES) {
        for (OutputEncoding encoding : ENCODES) {
            applyAndVerify(sfile, transform, chkType, encoding);
        }
    }
}
 
Example #12
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testResize() throws IOException {
    for (String sfile : FNAMES) {
        for (int[] exptSize : NEW_SIZES) {
            Transform transform = ImagesServiceFactory.makeResize(exptSize[0], exptSize[1]);
            for (OutputEncoding encoding : ENCODES) {
                Image image = imagesService.applyTransform(transform, readImage(sfile), encoding);
                assertTrue((exptSize[0] == image.getWidth()) || (exptSize[1] == image.getHeight()));
            }
        }
    }
}
 
Example #13
Source File: ImagesServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testCrop() throws IOException {
    ChkType chkType = ChkType.CROP;
    String cropLeftX = "0.0";
    String cropTopY = "0.0";
    String cropRightX = "0.5";
    String cropBottomY = "0.5";
    Transform transform = ImagesServiceFactory.makeCrop(new Float(cropLeftX), new Float(cropTopY), new Float(cropRightX), new Float(cropBottomY));
    for (OutputEncoding encoding : ENCODES) {
        applyAndVerify("pngAttach.png", transform, chkType, encoding);
    }
}