Java Code Examples for com.google.appengine.api.images.ImagesService.OutputEncoding#PNG

The following examples show how to use com.google.appengine.api.images.ImagesService.OutputEncoding#PNG . 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: 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());
}