Package com.google.appengine.api.images

Examples of com.google.appengine.api.images.ImagesService


  private static final long serialVersionUID = 1259406458178658440L;
 
  public Noticia(byte[] bs) {
    super();
    ImagesService service = ImagesServiceFactory.getImagesService();
    Transform transform = ImagesServiceFactory.makeImFeelingLucky();
    Image image = service.applyTransform(transform, ImagesServiceFactory.makeImage(bs));
    this.arquivo = new Blob(image.getImageData());
    this.dataCadastro = new Date();
  }
View Full Code Here


    if (null == blobKey) {
      sendError(res, "無法正常儲存上傳的檔案");
      return;
    }

    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey);

    String servingUrl = imagesService.getServingUrl(servingOptions);

    res.setStatus(HttpServletResponse.SC_OK);
    res.setContentType("application/json");

    // 二種方式都能存取上傳的圖檔
View Full Code Here

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    BlobstoreService blobService = BlobstoreServiceFactory
        .getBlobstoreService();
    ImagesService imageService = ImagesServiceFactory.getImagesService();
    try {
      String alias = req.getParameter("alias");
      News obj = NewsModel.getById(alias);
      if (obj != null) {
        String action = req.getParameter("action");
        String title = req.getParameter("title");
        String content = req.getParameter("content");
        String source = req.getParameter("source");
        String category = req.getParameter("category");
        String tags = req.getParameter("tags");
        if (action != null && action.equals("edit")) {
          obj.setTitle(title);
          obj.setAlias(StringHelper.replaceVietnamese(title));
          obj.setContent(content);
          obj.setSource(source);

          /*
           * process thumb image
           */
          try {
            Map<String, List<BlobKey>> blobs = blobService
                .getUploads(req);
            List<BlobKey> blobKeys = blobs.get("img");
            if (blobKeys != null && blobKeys.size() > 0) {
              for (BlobKey blobKey : blobKeys) {
                byte[] arr = blobService.fetchData(blobKey, 0,
                    20);
                if (arr.length > 0) {
                  obj.setThumb(imageService
                      .getServingUrl(blobKey));
                }
              }
            }
          } catch (Exception e) {
View Full Code Here

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    BlobstoreService blobService = BlobstoreServiceFactory
        .getBlobstoreService();
    ImagesService imageService = ImagesServiceFactory.getImagesService();
    try {
      String action = req.getParameter("action");
      String title = req.getParameter("title");
      String content = req.getParameter("content");
      String source = req.getParameter("source");
      String category = req.getParameter("category");
      String tags = req.getParameter("tags");
      News obj = new News();
      if (action != null && action.equals("add")) {
        obj.setTitle(title);
        obj.setAlias(StringHelper.replaceVietnamese(title));
        News checkObj = NewsModel.getById(obj.getAlias());
        if (checkObj != null) {
          obj.setAlias(obj.getAlias() + "-"
              + IdUniqueHelper.getId().toLowerCase());
        }
        obj.setContent(content);
        obj.setSource(source);

        /*
         * process thumb image
         */
        try {
          Map<String, List<BlobKey>> blobs = blobService
              .getUploads(req);
          List<BlobKey> blobKeys = blobs.get("img");
          if (blobKeys != null && blobKeys.size() > 0) {
            for (BlobKey blobKey : blobKeys) {
              byte[] arr = blobService.fetchData(blobKey, 0, 20);
              if (arr.length > 0) {
                obj.setThumb(imageService
                    .getServingUrl(blobKey));
              }
            }
          }
        } catch (Exception e) {
View Full Code Here

   * @param url the url to set
   */
  public void setUrl(String url) {
    URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
    FileService fileService = FileServiceFactory.getFileService();
    ImagesService imagesService = ImagesServiceFactory.getImagesService();

    HTTPResponse fetchResponse;
    try {
      fetchResponse = fetchService.fetch(new URL(url));
      Image originalImage = ImagesServiceFactory.makeImage(fetchResponse.getContent());

      AppEngineFile file = fileService.createNewBlobFile("image/" + originalImage.getFormat());
      FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
      ByteBuffer buffer = ByteBuffer.wrap(originalImage.getImageData());
      writeChannel.write(buffer);
      writeChannel.closeFinally();
      BlobKey key = fileService.getBlobKey(file);
      String servingURL = imagesService.getServingUrl(key);
      if (servingURL != null) {
        this.url = servingURL;
      }
      else {
        System.err.println("Unable to create a URL for the image");
View Full Code Here

    public void deleteImage(Long id) {
        getObjectify().delete(getImageById(id));
    }
   
    public byte[] getIconFromImage(byte[] image) {
        ImagesService imagesService = ImagesServiceFactory.getImagesService();
        com.google.appengine.api.images.Image srcImage = ImagesServiceFactory.makeImage(image);
        Transform resize = ImagesServiceFactory.makeResize(ICON_SIZE, ICON_SIZE);
        Transform ifl = ImagesServiceFactory.makeImFeelingLucky();
        com.google.appengine.api.images.Image icon = imagesService.applyTransform(resize, srcImage);
        icon = imagesService.applyTransform(ifl, icon);
        return icon.getImageData();
    }
View Full Code Here

   
    return new ProfilePictureData(imageData, Encoding.md5(imageData), profilePicture.getWidth(), profilePicture.getHeight());
  }
 
  private static Image normalizeProfilePicture(Image uploadedImage) {
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    Transform resize = ImagesServiceFactory.makeResize(250, 500);
   
    OutputSettings jpeg = new OutputSettings(OutputEncoding.JPEG);
   
    Image profileImage = imagesService.applyTransform(resize, uploadedImage, jpeg);
    if (profileImage.getFormat() != Format.JPEG)
      throw new AssertionError("Wrong format: " + profileImage.getFormat());
   
    return profileImage;
  }
View Full Code Here

      res.setHeader("Cache-Control", "public, max-age=86400");
      res.setHeader("Expires", cal.getTime().toString());
      if (req.getParameter("key") != null
          && req.getParameter("size") != null) {
        BlobKey blobKey = new BlobKey(req.getParameter("key"));
        ImagesService imagesService = ImagesServiceFactory
            .getImagesService();
        res.sendRedirect(imagesService.getServingUrl(blobKey) + "=s"
            + req.getParameter("size"));
      } else {
        res.getWriter().print("/image/tube.png");
      }
    } catch (Exception e) {
View Full Code Here

      
        if (blobKey == null) {

        } else {

          ImagesService imagesService = ImagesServiceFactory.getImagesService();
          String imageUrl = imagesService.getServingUrl(blobKey);

          UserService userService = UserServiceFactory.getUserService();
            // TODO: Add a better check for whether the user is logged in or not
          // Don't even let the user upload or get here
          User user = userService.getCurrentUser();
View Full Code Here

     *              underlying exception will propagate out otherwise
     *              the result of onFail will be returned as the URL.
     * @return a URL that can serve the image dynamically.
     */
    public static String getServingUrl(BlobKey blobKey, Map<String, Object> options) {
        ImagesService images = ImagesServiceFactory.getImagesService();
        int retries = options.containsKey("retry") ((Number)options.get("retry")).intValue() : 0;
        int origRetries = retries;
        Closure<?> onFail = options.containsKey("onFail") ? (Closure<?>) options.get("onFail") : null;
        Closure<?> onRetry = options.containsKey("onRetry") ? (Closure<?>) options.get("onRetry") : null;
        while (true) {
            Exception ex = null;
            try {
                return images.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));
            } catch (ApiProxy.ApiDeadlineExceededException adee) {
                ex = adee;
            } catch (IllegalArgumentException iae) {
                ex = iae;
            } catch (ImagesServiceFailureException isfe) {
View Full Code Here

TOP

Related Classes of com.google.appengine.api.images.ImagesService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.