imagemodule.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,229 行 · 第 1/4 页

JAVA
2,229
字号
					  float gammaBefore, float gammaAfter)  {    // this is a no-op in PHP; apparently the GD library dropped    // support for gamma correction between v1.8 and v2.0    return true;  }  /**   * Output GD2 image to browser or file   */  public static void imagegd2(QuercusImage image, @Optional Path file)  {    throw new QuercusException("imagegd2 is not implemented");  }  /**   * Output GD image to browser or file   */  public static void imagegd(QuercusImage image, @Optional Path file)  {    throw new QuercusException("imagegd is not implemented");  }  /**   * Output image to browser or file   */  public static boolean imagegif(Env env, QuercusImage image,				 @Optional Path path)  {    try {      if (path != null) {	WriteStream os = path.openWrite();		try {	  ImageIO.write(image._bufferedImage, "gif", os);	} finally {	  os.close();	}      }      else	ImageIO.write(image._bufferedImage, "gif", env.getOut());            return true;    }    catch (IOException e) {      log.log(Level.FINE, e.toString(), e);            return false;    }  }  // XXX: imagegrabscreen  // XXX: imagegrabwindow  /**   * Enable or disable interlace   */  public static boolean imageinterlace(QuercusImage image,                                       @Optional Boolean enable)  {    if (enable != null)      image.setInterlace(enable);        // no-op, can safely ignore (just makes images that load top-down)    return true;  }  /**   * Finds whether an image is a truecolor image   */  public static boolean imageistruecolor(QuercusImage image)  {    return true;  }  /**   * Output image to browser or file   */  public static boolean imagejpeg(Env env,				  QuercusImage image,				  @Optional Path path,				  @Optional int quality)  {    try {      if (path != null) {	WriteStream os = path.openWrite();		try {	  ImageIO.write(image._bufferedImage, "jpeg", os);	} finally {	  os.close();	}      }      else	ImageIO.write(image._bufferedImage, "jpeg", env.getOut());            return true;    }    catch (IOException e) {      log.log(Level.FINE, e.toString(), e);            return false;    }  }  /**   * Set the alpha blending flag to use the bundled libgd layering effects   */  public static boolean imagelayereffect(QuercusImage image, int effect)  {    // XXX: there is no documentation for how this function ought to work    // http://us3.php.net/manual/en/function.imagelayereffect.php    return false;  }  /**   * Draw a line   */  public static boolean imageline(QuercusImage image,				  int x1, int y1, int x2, int y2, int color)  {    image.stroke(new Line2D.Float(x1, y1, x2, y2), color);    return true;  }  /**   * Load a new font   */  public static long imageloadfont(Path file)  {    throw new QuercusException("imageloadfont() not implemented");  }  /**   * Copy the palette from one image to another   */  public static boolean imagepalettecopy(QuercusImage source,					 QuercusImage dest)  {    return true;  }  /**   * Output a PNG image to either the browser or a file   */  public static boolean imagepng(Env env,				 QuercusImage image,				 @Optional Path path)  {    try {      if (path != null) {	WriteStream os = path.openWrite();		try {	  ImageIO.write(image._bufferedImage, "png", os);	} finally {	  os.close();	}      }      else	ImageIO.write(image._bufferedImage, "png", env.getOut());            return true;    }    catch (IOException e) {      log.log(Level.FINE, e.toString(), e);            return false;    }  }    /**   * Draw a polygon   */  public static boolean imagepolygon(Env env,                                     QuercusImage image,                                     ArrayValue points,                                     int numPoints, int color)  {    image.stroke(arrayToPolygon(env, points, numPoints), color);    return true;  }  /**   * Give the bounding box of a text rectangle using PostScript Type1 fonts   */  public static ArrayValue imagepsbbox(String text, int font, int size,				       @Optional int space,				       @Optional int tightness,				       @Optional float angle)  {    throw new QuercusException("imagepsbbox() not implemented");  }  /**   * Make a copy of an already loaded font for further modification   */  public static int imagepscopyfont(Value fontIndex)  {    throw new QuercusException("imagepscopyfont() not implemented");  }  /**   * Change the character encoding vector of a font   */  public static boolean imagepsencodefont(Value fontIndex, Path encodingFile)  {    throw new QuercusException("imagepsencodefont() not implemented");  }  /**   * Extend or condense a font   */  public static boolean imagepsextendfont(int fontIndex, float extend)  {    throw new QuercusException("imagepsextendfont() not implemented");  }  /**   * Free memory used by a PostScript Type 1 font   */  public static boolean imagepsfreefont(Value fontIndex)  {    throw new QuercusException("imagepsfreefont() not implemented");  }  /**   * Load a PostScript Type 1 font from file   */  public static Value imagepsloadfont(Path fontFile)  {    throw new QuercusException("imagepsloadfont() not implemented");  }  /**   * Slant a font   */  public static boolean imagepsslantfont(Value fontIndex, float slant)  {    throw new QuercusException("imagepsslantfont() not implemented");  }  /**   * To draw a text string over an image using PostScript Type1 fonts   */  public static ArrayValue imagepstext(QuercusImage image,				       String text,				       Value fontIndex,				       int size, int fg, int bg, int x, int y,				       @Optional int space,				       @Optional int tightness,				       @Optional float angle,				       @Optional int antialias_steps)  {    throw new QuercusException("imagepstext() not implemented");  }  /**   * Draw a rectangle   */  public static boolean imagerectangle(QuercusImage image, int x1, int y1,				       int x2, int y2, int color)  {    if (x2 < x1) { int tmp = x1; x1 = x2; x2 = tmp; }    if (y2 < y1) { int tmp = y1; y1 = y2; y2 = tmp; }    image.stroke(new Rectangle2D.Float(x1, y1, x2-x1, y2-y1), color);    return true;  }  /**   * Rotate an image with a given angle   */  public static boolean imagerotate(QuercusImage image, float angle,				    int backgroundColor,				    @Optional int ignoreTransparent)  {    // this function is broken on most PHP installs: "Note: This    // function is only available if PHP is compiled with the bundled    // version of the GD library."    return false;  }  /**   * Set the flag to save full alpha channel information (as opposed to   * single-color transparency) when saving PNG images   */  public static boolean imagesavealpha(QuercusImage image, boolean set)  {    // no-op since we currently only support true-color, full-alpha channel    return true;  }  /**   * Set the brush image for line drawing   */  public static boolean imagesetbrush(QuercusImage image, QuercusImage brush)  {    image.setBrush(brush);    return true;  }  /**   * Set a single pixel   */  public static boolean imagesetpixel(QuercusImage image,				      int x, int y, int color)  {    image.setPixel(x, y, color);    return true;  }  /**   * Set the style for line drawing   */  public static boolean imagesetstyle(Env env,                                      QuercusImage image,                                      ArrayValue style)  {    image.setStyle(env, style);    return true;  }  /**   * Set the thickness for line   */  public static boolean imagesetthickness(QuercusImage image, int thickness)  {    image.setThickness(thickness);    return true;  }  // XXX: imagesettile  /**   * Draw a string horizontally   */  public static boolean imagestring(QuercusImage image, int font,				  int x, int y, String s, int color)  {    Graphics2D g = image.getGraphics();    g.setColor(intToColor(color));    Font awtfont = image.getFont(font);    int height = image.getGraphics().getFontMetrics(awtfont).getAscent();    g.setFont(awtfont);    g.drawString(s, x, y+height);        return true;  }  /**   * Draw a string vertically   */  public static boolean imagestringup(QuercusImage image, int font,				      int x, int y, String s, int color)  {    Graphics2D g = image.getGraphics();    AffineTransform oldTransform = g.getTransform();        g.translate(x, y);    //    g.rotate(-1 * Math.PI / 2);    g.rotate(-1 * Math.PI / 2);    g.setColor(intToColor(color));    Font awtfont = image.getFont(font);    int height = image.getGraphics().getFontMetrics(awtfont).getAscent();    g.setFont(awtfont);    g.drawString(s, 0, 0+height);    g.setTransform(oldTransform);        return true;  }  /**   * Returns the width of the image.   */  public static int imagesx(@NotNull QuercusImage image)  {    if (image == null)      return 0;        return image.getWidth();  }  /**   * Returns the height of the image.   */  public static int imagesy(@NotNull QuercusImage image)  {    if (image == null)      return 0;        return image.getHeight();  }  /**   * general affine transformation   */  public static boolean image_transform(QuercusImage image,					double m00, double m10,					double m01, double m11,					double m02, double m12)  {    if (image == null)      return false;    AffineTransform transform      = new AffineTransform(m00, m10, m01, m11, m02, m12);    image.getGraphics().transform(transform);        return true;  }  /**   * scaling transformation   */  public static boolean image_transform_scale(QuercusImage image,					      double sx, double sy)  {    if (image == null)      return false;    image.getGraphics().scale(sx, sy);        return true;  }  /**   * shearing transformation   */  public static boolean image_transform_shear(QuercusImage image,					      double shx, double shy)  {    if (image == null)      return false;    image.getGraphics().shear(shx, shy);        return true;  }  /**   * translation transformation   */  public static boolean image_transform_translate(QuercusImage image,						  double x, double y)  {    if (image == null)      return false;    image.getGraphics().translate(x, y);        return true;  }  /**   * draws a true type font image   */  public static Value imagettfbbox(Env env,				   double size,				   double angle,				   String fontFile,				   String text)  {    return imageftbbox(env, size, angle, fontFile, text, null);  }  /**   * draws a true type font image   */  public static Value imagettftext(Env env,				   @NotNull QuercusImage image,				   double size,				   double angle,				   int x,				   int y,				   int color,				   String fontFile,				   String text)  {    return imagefttext(env, image, size, angle, x, y,		       color, fontFile, text, null);  }  /**   * Returns the imagetypes.   */  public static long imagetypes()  {    return IMG_GIF | IMG_JPG | IMG_PNG;  }  /**   * Output image to browser or file   */  public static void imagewbmp(QuercusImage image,			       @Optional Path filename,			       @Optional int threshhold)  {    throw new QuercusException("not supported");  }  // XXX: imagexbm  /**   * Embe into single tags.   */  public static boolean iptcembed(String iptcdata, String jpegFileName,				  @Optional int spool)  {    throw new QuercusException("iptcembed is not [yet] supported");  }  /**   * Convert JPEG image file to WBMP image file   */  public static void jpeg2wbmp(String jpegFilename,			       String wbmpName,			       int d_height,			       int d_width,			       int threshhold)  {    throw new QuercusException("not supported");  }  /**   * Convert PNG image file to WBM   */  public static void png2wbmp(String pngFilename,			      String wbmpName,			      int d_height,			      int d_width,			      int threshhold)  {    throw new QuercusException("not supported");  }  // Private Helpers ////////////////////////////////////////////////////////    private static Polygon arrayToPolygon(Env env,                                        ArrayValue points,                                        int numPoints)  {    Polygon polygon = new Polygon();        Iterator<Value> iter = points.getValueIterator(env);        for(int i = 0; i < numPoints; i++) {      int x = iter.next().toInt();      int y = iter.next().toInt();      polygon.addPoint(x, y);    }    return polygon;  }  private static Color intToColor(int argb)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?