示例#1
0
  /**
   * wp_load_image() - Load an image which PHP Supports.
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param string $file Filename of the image to load
   * @return resource The resulting image resource on success, Error string on failure.
   */
  public Object wp_load_image(Object fileObj) {
    int image = 0;

    // Modified by Numiton
    String file;

    if (is_numeric(fileObj)) {
      file =
          strval(
              getIncluded(PostPage.class, gVars, gConsts)
                  .get_attached_file(intval(fileObj), false));
    } else {
      file = strval(fileObj);
    }

    if (!FileSystemOrSocket.file_exists(gVars.webEnv, file)) {
      return QStrings.sprintf(
          getIncluded(L10nPage.class, gVars, gConsts).__("File \'%s\' doesn\'t exist?", "default"),
          file);
    }

    if (!true) /*Modified by Numiton*/ {
      return getIncluded(L10nPage.class, gVars, gConsts)
          .__("The GD image library is not installed.", "default");
    }

    // Set artificially high because GD uses uncompressed images in memory
    Options.ini_set(gVars.webEnv, "memory_limit", "256M");
    image =
        Image.imagecreatefromstring(
            gVars.webEnv, FileSystemOrSocket.file_get_contents(gVars.webEnv, file));

    if (!is_resource(image)) {
      return QStrings.sprintf(
          getIncluded(L10nPage.class, gVars, gConsts).__("File \'%s\' is not an image.", "default"),
          file);
    }

    return image;
  }
示例#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);
    }
  }