com.google.appengine.api.images.ImagesServiceFactory Java Examples
The following examples show how to use
com.google.appengine.api.images.ImagesServiceFactory.
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 |
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: ImagesServiceTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@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 #3
Source File: TransformationsTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testResizeWithCrop() throws IOException { int resizedWidth = 300; int resizedHeight = 200; Image originalImage = readImage(CAPEDWARF_PNG); Transform resize = ImagesServiceFactory.makeResize(resizedWidth, resizedHeight, 0.5f, 0.5f); Image resizedImage = imagesService.applyTransform(resize, originalImage); assertEquals(resizedWidth, resizedImage.getWidth()); assertEquals(resizedHeight, resizedImage.getHeight()); originalImage = readImage(CAPEDWARF_PNG); resize = ImagesServiceFactory.makeResize(resizedWidth, resizedHeight, 0.5, 0.5); resizedImage = imagesService.applyTransform(resize, originalImage); assertEquals(resizedWidth, resizedImage.getWidth()); assertEquals(resizedHeight, resizedImage.getHeight()); }
Example #4
Source File: TransformationsTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@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 #5
Source File: CompositeTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testTransform() throws IOException { CompositeTransform transform = ImagesServiceFactory.makeCompositeTransform(); transform.concatenate(ImagesServiceFactory.makeHorizontalFlip()); transform.concatenate(ImagesServiceFactory.makeHorizontalFlip()); Image originalImage = readImage(CAPEDWARF_PNG); Image result = imagesService.applyTransform(transform, originalImage); assertImages(transform, originalImage, result); transform = ImagesServiceFactory.makeCompositeTransform(newArrayList(ImagesServiceFactory.makeVerticalFlip(), ImagesServiceFactory.makeVerticalFlip())); originalImage = readImage(CAPEDWARF_PNG); result = imagesService.applyTransform(transform, originalImage); assertImages(transform, originalImage, result); }
Example #6
Source File: PhotoServiceManager.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
public String getPhotoDisplayUrl(BlobKey blobKey) { ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(blobKey); options.imageSize(configManager.getPhotoThumbnailSizeInPixels()); options.crop(configManager.isPhotoThumbnailCrop()); try { return ImagesServiceFactory.getImagesService().getServingUrl(options); } catch (ImagesServiceFailureException e) { logger.severe("Failed to get image serving url: " + e.getMessage()); return ""; } }
Example #7
Source File: ImagesServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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); } }
Example #8
Source File: ImagesServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 #9
Source File: ImagesServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 #10
Source File: ImagesServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 |
@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 #12
Source File: TransformationsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testResizeWithStretch() throws IOException { int resizedWidth = 300; int resizedHeight = 200; Image originalImage = readImage(CAPEDWARF_PNG); Transform resize = ImagesServiceFactory.makeResize(resizedWidth, resizedHeight, true); Image resizedImage = imagesService.applyTransform(resize, originalImage); assertEquals(resizedWidth, resizedImage.getWidth()); assertEquals(resizedHeight, resizedImage.getHeight()); }
Example #13
Source File: TransformationsTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 #14
Source File: CompositeTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 #15
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testResize() throws IOException { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); int resizeWidth = 150; int resizeHeigh = 150; Transform transform = ImagesServiceFactory.makeResize(resizeWidth, resizeHeigh); assertTransformation(transform, "Resize"); }
Example #16
Source File: GalleryServiceImpl.java From appinventor-extensions with Apache License 2.0 | 5 votes |
/** * It will return a dev server serving url for given image url * @param url image url */ @Override public String getBlobServingUrl(String url) { BlobKey bk = BlobstoreServiceFactory.getBlobstoreService().createGsBlobKey(url); String u = null; try { u = ImagesServiceFactory.getImagesService().getServingUrl(bk); } catch (Exception IllegalArgumentException) { LOG.info("Could not read blob"); } return u; }
Example #17
Source File: IntegrationTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testHorizontalFlip() throws IOException { Image image = readImage("capedwarf.png"); Transform horizontalFlip = ImagesServiceFactory.makeHorizontalFlip(); Image flippedImage = imagesService.applyTransform(horizontalFlip, image); assertNotNull(flippedImage); }
Example #18
Source File: CompositeTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@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 #19
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testRotate() throws IOException { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); int rotageDegree = 90; Transform transform = ImagesServiceFactory.makeRotate(rotageDegree); assertTransformation(transform, "Rotate"); }
Example #20
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testCrop() throws IOException { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); double cropLeftX = 0.0; double cropTopY = 0.0; double cropRightX = 0.5; double cropBottomY = 0.5; Transform transform = ImagesServiceFactory.makeCrop( cropLeftX, cropTopY, cropRightX, cropBottomY ); assertTransformation(transform, "Crop"); }
Example #21
Source File: CompositeTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testDefault() throws IOException { // w - 200, h - 143 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); assertImages(null, originalImage, ci); }
Example #22
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test public void testVerticalFlip() throws IOException { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); Transform transform = ImagesServiceFactory.makeVerticalFlip(); assertTransformation(transform, "VerticalFlip"); }
Example #23
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test public void testHorizontalFlip() throws IOException { assumeEnvironment(Environment.APPSPOT, Environment.CAPEDWARF); Transform transform = ImagesServiceFactory.makeHorizontalFlip(); assertTransformation(transform, "HorizontalFlip"); }
Example #24
Source File: TifImageTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test public void testFeelingLucky() throws IOException { assumeEnvironment(Environment.APPSPOT); Transform transform = ImagesServiceFactory.makeImFeelingLucky(); assertTransformation(transform, "ImFeelingLucky"); }
Example #25
Source File: ImagesServlet.java From java-docs-samples with Apache License 2.0 | 4 votes |
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { // [START original_image] // Read the image.jpg resource into a ByteBuffer. FileInputStream fileInputStream = new FileInputStream(new File("WEB-INF/image.jpg")); FileChannel fileChannel = fileInputStream.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocate((int) fileChannel.size()); fileChannel.read(byteBuffer); byte[] imageBytes = byteBuffer.array(); // Write the original image to Cloud Storage gcsService.createOrReplace( new GcsFilename(bucket, "image.jpeg"), new GcsFileOptions.Builder().mimeType("image/jpeg").build(), ByteBuffer.wrap(imageBytes)); // [END original_image] // [START resize] // Get an instance of the imagesService we can use to transform images. ImagesService imagesService = ImagesServiceFactory.getImagesService(); // Make an image directly from a byte array, and transform it. Image image = ImagesServiceFactory.makeImage(imageBytes); Transform resize = ImagesServiceFactory.makeResize(100, 50); Image resizedImage = imagesService.applyTransform(resize, image); // Write the transformed image back to a Cloud Storage object. gcsService.createOrReplace( new GcsFilename(bucket, "resizedImage.jpeg"), new GcsFileOptions.Builder().mimeType("image/jpeg").build(), ByteBuffer.wrap(resizedImage.getImageData())); // [END resize] // [START rotate] // Make an image from a Cloud Storage object, and transform it. BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/" + bucket + "/image.jpeg"); Image blobImage = ImagesServiceFactory.makeImageFromBlob(blobKey); Transform rotate = ImagesServiceFactory.makeRotate(90); Image rotatedImage = imagesService.applyTransform(rotate, blobImage); // Write the transformed image back to a Cloud Storage object. gcsService.createOrReplace( new GcsFilename(bucket, "rotatedImage.jpeg"), new GcsFileOptions.Builder().mimeType("image/jpeg").build(), ByteBuffer.wrap(rotatedImage.getImageData())); // [END rotate] // [START servingUrl] // Create a fixed dedicated URL that points to the GCS hosted file ServingUrlOptions options = ServingUrlOptions.Builder.withGoogleStorageFileName("/gs/" + bucket + "/image.jpeg") .imageSize(150) .crop(true) .secureUrl(true); String url = imagesService.getServingUrl(options); // [END servingUrl] // Output some simple HTML to display the images we wrote to Cloud Storage // in the browser. PrintWriter out = resp.getWriter(); out.println("<html><body>\n"); out.println( "<img src='//storage.cloud.google.com/" + bucket + "/image.jpeg' alt='AppEngine logo' />"); out.println( "<img src='//storage.cloud.google.com/" + bucket + "/resizedImage.jpeg' alt='AppEngine logo resized' />"); out.println( "<img src='//storage.cloud.google.com/" + bucket + "/rotatedImage.jpeg' alt='AppEngine logo rotated' />"); out.println("<img src='" + url + "' alt='Hosted logo' />"); out.println("</body></html>\n"); }
Example #26
Source File: MakeImageTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test public void blobKeyImage() throws IOException { Image i1 = ImagesServiceFactory.makeImageFromBlob(new BlobKey("gs/bucket/123")); Image i2 = ImagesServiceFactory.makeImageFromFilename("/gs/bucket/123"); assertEquals(i1, i2); // should compare blob keys }
Example #27
Source File: MakeImageTest.java From appengine-tck with Apache License 2.0 | 4 votes |
private void assertMakeImageCanReadImage(byte[] imageData) { Image image = ImagesServiceFactory.makeImage(imageData); assertNotNull(image); }
Example #28
Source File: ImagesServiceTestBase.java From appengine-tck with Apache License 2.0 | 4 votes |
@Before public void init() throws Exception { imagesService = ImagesServiceFactory.getImagesService(); }
Example #29
Source File: ImagesServiceTestBase.java From appengine-tck with Apache License 2.0 | 4 votes |
protected Image readImage(String filename) throws IOException { return ImagesServiceFactory.makeImage(toByteArray(getImageStream(filename))); }
Example #30
Source File: GalleryServiceImpl.java From appinventor-extensions with Apache License 2.0 | 4 votes |
/** * when an app is published/updated, we need to move the image * that was temporarily uploaded into projects/projectid/image * into the gallery image * @param app gallery app */ private void setGalleryAppImage(GalleryApp app) { // best thing would be if GCS has a mv op, we can just do that. // don't think that is there, though, so for now read one and write to other // First, read the file from projects name boolean lockForRead = false; //String projectImageKey = app.getProjectImageKey(); GallerySettings settings = loadGallerySettings(); String projectImageKey = settings.getProjectImageKey(app.getProjectId()); try { GcsService gcsService = GcsServiceFactory.createGcsService(); //GcsFilename filename = new GcsFilename(GalleryApp.GALLERYBUCKET, projectImageKey); GcsFilename filename = new GcsFilename(settings.getBucket(), projectImageKey); GcsInputChannel readChannel = gcsService.openReadChannel(filename, 0); InputStream gcsis = Channels.newInputStream(readChannel); byte[] buffer = new byte[8000]; int bytesRead = 0; ByteArrayOutputStream bao = new ByteArrayOutputStream(); while ((bytesRead = gcsis.read(buffer)) != -1) { bao.write(buffer, 0, bytesRead); } // close the project image file readChannel.close(); // if image is greater than 200 X 200, it will be scaled (200 X 200). // otherwise, it will be stored as origin. byte[] oldImageData = bao.toByteArray(); byte[] newImageData; ImagesService imagesService = ImagesServiceFactory.getImagesService(); Image oldImage = ImagesServiceFactory.makeImage(oldImageData); //if image size is too big, scale it to a smaller size. if(oldImage.getWidth() > 200 && oldImage.getHeight() > 200){ Transform resize = ImagesServiceFactory.makeResize(200, 200); Image newImage = imagesService.applyTransform(resize, oldImage); newImageData = newImage.getImageData(); }else{ newImageData = oldImageData; } // set up the cloud file (options) // After publish, copy the /projects/projectId image into /apps/appId //String galleryKey = app.getImageKey(); String galleryKey = settings.getImageKey(app.getGalleryAppId()); //GcsFilename outfilename = new GcsFilename(GalleryApp.GALLERYBUCKET, galleryKey); GcsFilename outfilename = new GcsFilename(settings.getBucket(), galleryKey); GcsFileOptions options = new GcsFileOptions.Builder().mimeType("image/jpeg") .acl("public-read").cacheControl("no-cache").build(); GcsOutputChannel writeChannel = gcsService.createOrReplace(outfilename, options); writeChannel.write(ByteBuffer.wrap(newImageData)); // Now finalize writeChannel.close(); } catch (IOException e) { // TODO Auto-generated catch block LOG.log(Level.INFO, "FAILED WRITING IMAGE TO GCS"); e.printStackTrace(); } }