Exemple #1
0
  /**
   * wp_generate_attachment_metadata() - Generate post Image attachment Metadata
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param int $attachment_id Attachment Id to process
   * @param string $file Filepath of the Attached image
   * @return mixed Metadata for attachment
   */
  public Object wp_generate_attachment_metadata(int attachment_id, String file) {
    StdClass attachment = null;
    Array<Object> metadata = new Array<Object>();
    Array<Object> imagesize = new Array<Object>();
    Array<Object> sizes = new Array<Object>();
    Array<Object> resized = new Array<Object>();
    Object size = null;
    Array<Object> image_meta;
    attachment =
        (StdClass)
            getIncluded(PostPage.class, gVars, gConsts)
                .get_post(attachment_id, gConsts.getOBJECT(), "raw");
    metadata = new Array<Object>();

    if (QRegExPerl.preg_match(
            "!^image/!", getIncluded(PostPage.class, gVars, gConsts).get_post_mime_type(attachment))
        && file_is_displayable_image(file)) {
      imagesize = QImage.getimagesize(gVars.webEnv, file);
      metadata.putValue("width", imagesize.getValue(0));
      metadata.putValue("height", imagesize.getValue(1));
      new ListAssigner<Object>() {
        public Array<Object> doAssign(Array<Object> srcArray) {
          if (strictEqual(srcArray, null)) {
            return null;
          }

          wp_generate_attachment_metadata_uwidth = srcArray.getValue(0);
          wp_generate_attachment_metadata_uheight = srcArray.getValue(1);

          return srcArray;
        }
      }.doAssign(
          wp_shrink_dimensions(
              intval(metadata.getValue("width")), intval(metadata.getValue("height")), 128, 96));
      metadata.putValue(
          "hwstring_small",
          "height=\'"
              + strval(wp_generate_attachment_metadata_uheight)
              + "\' width=\'"
              + strval(wp_generate_attachment_metadata_uwidth)
              + "\'");
      metadata.putValue("file", file);

      // make thumbnails and other intermediate sizes
      sizes =
          new Array<Object>(new ArrayEntry<Object>("thumbnail"), new ArrayEntry<Object>("medium"));
      sizes =
          (Array<Object>)
              getIncluded(PluginPage.class, gVars, gConsts)
                  .apply_filters("intermediate_image_sizes", sizes);

      for (Map.Entry javaEntry147 : sizes.entrySet()) {
        size = javaEntry147.getValue();
        resized =
            getIncluded(MediaPage.class, gVars, gConsts)
                .image_make_intermediate_size(
                    file,
                    intval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_size_w")),
                    intval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_size_h")),
                    booleanval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_crop")));

        if (booleanval(resized)) {
          metadata.getArrayValue("sizes").putValue(size, resized);
        }
      }

      // fetch additional metadata from exif/iptc
      image_meta = wp_read_image_metadata(file);

      if (booleanval(image_meta)) {
        metadata.putValue("image_meta", image_meta);
      }
    }

    return getIncluded(PluginPage.class, gVars, gConsts)
        .apply_filters("wp_generate_attachment_metadata", metadata);
  }
Exemple #2
0
  /**
   * wp_crop_image() - Crop an Image to a given size.
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param int $src_file The source file
   * @param int $src_x The start x position to crop from
   * @param int $src_y The start y position to crop from
   * @param int $src_w The width to crop
   * @param int $src_h The height to crop
   * @param int $dst_w The destination width
   * @param int $dst_h The destination height
   * @param int $src_abs If the source crop points are absolute
   * @param int $dst_file The destination file to write to
   * @return string New filepath on success, String error message on failure
   */
  public String wp_crop_image(
      Object src_fileObj,
      int src_x,
      int src_y,
      int src_w,
      int src_h,
      int dst_w,
      int dst_h,
      boolean src_abs,
      String dst_file) {
    Object src = null;
    int dst = 0;
    String src_file;

    // Modified by Numiton
    if (is_numeric(src_fileObj)) { // Handle int as attachment ID
      src_file =
          strval(
              getIncluded(PostPage.class, gVars, gConsts)
                  .get_attached_file(intval(src_fileObj), false));
    } else {
      src_file = strval(src_fileObj);
    }

    src = wp_load_image(src_file);

    if (!is_resource(src)) {
      return strval(src);
    }

    dst = Image.imagecreatetruecolor(gVars.webEnv, dst_w, dst_h);

    if (src_abs) {
      src_w = src_w - src_x;
      src_h = src_h - src_y;
    }

    if (true) /*Modified by Numiton*/ {
      Image.imageantialias(gVars.webEnv, dst, true);
    }

    Image.imagecopyresampled(
        gVars.webEnv, dst, intval(src), 0, 0, src_x, src_y, dst_w, dst_h, src_w, src_h);
    Image.imagedestroy(gVars.webEnv, intval(src)); // Free up memory

    if (!booleanval(dst_file)) {
      dst_file =
          Strings.str_replace(
              FileSystemOrSocket.basename(src_file),
              "cropped-" + FileSystemOrSocket.basename(src_file),
              src_file);
    }

    dst_file = QRegExPerl.preg_replace("/\\.[^\\.]+$/", ".jpg", dst_file);

    if (Image.imagejpeg(gVars.webEnv, dst, dst_file)) {
      return dst_file;
    } else {
      return strval(false);
    }
  }