类 ImageUtils

java.lang.Object
com.publiccms.common.tools.ImageUtils

public class ImageUtils extends Object
ImageUtils
  • 字段详细资料

    • log

      private static final org.apache.commons.logging.Log log
    • FORMAT_NAME_PNG

      public static final String FORMAT_NAME_PNG
      另请参阅:
    • FORMAT_NAME_JPG

      public static final String FORMAT_NAME_JPG
      另请参阅:
    • FORMAT_NAME_WEBP

      public static final String FORMAT_NAME_WEBP
      另请参阅:
    • FORMAT_NAME_SVG

      public static final String FORMAT_NAME_SVG
      另请参阅:
    • DEFAULT_FORMAT_NAME

      public static final String DEFAULT_FORMAT_NAME
      另请参阅:
  • 构造器详细资料

    • ImageUtils

      private ImageUtils()
  • 方法详细资料

    • generateImageData

      public static String generateImageData(int width, int height, String text) throws IOException
      参数:
      width -
      height -
      text -
      返回:
      base64 encoded picture
      抛出:
      IOException
    • drawImage

      public static void drawImage(int width, int height, String text, OutputStream outputStream) throws IOException
       @RequestMapping(value = "getCaptchaImage")
       public ResponseEntity<StreamingResponseBody> getCaptchaImage(HttpSession session) {
           String captcha = VerificationUtils.getRandomString("ABCDEFGHJKMNPQRSTUVWXYZ23456789", 4);
           session.setAttribute("captcha", captcha);
           StreamingResponseBody body = new StreamingResponseBody() {
               @Override
               public void writeTo(OutputStream outputStream) throws IOException {
                   ImageUtils.drawImage(120, 30, captcha, outputStream);
               }
           };
           return ResponseEntity.ok().body(body);
       }
       
       @PostMapping("doLogin")
       public String login(@RequestAttribute SysSite site, HttpSession session, String username, String password, String captcha, String returnUrl, Long clientId, String uuid,
               HttpServletRequest request, ModelMap model) {
           String sessionCaptcha = (String) session.getAttribute("captcha");
           session.removeAttribute("captcha");
           if (null != sessionCaptcha && sessionCaptcha.equalsIgnoreCase(captcha)) {
               // login code
           } else {
               return CommonUtils.joinString(UrlBasedViewResolver.REDIRECT_URL_PREFIX, "login.html");
           }
       }
       
      参数:
      width -
      height -
      text -
      outputStream -
      抛出:
      IOException
    • shearX

      private static void shearX(Graphics g, int w1, int h1, Color color)
    • getRandColor

      private static Color getRandColor(int fc, int bc)
    • getFont

      private static Font getFont(int size)
    • webp2Image

      public static void webp2Image(InputStream webpInputStream, boolean png, String imageFilepath) throws IOException
      抛出:
      IOException
    • webp2Image

      public static void webp2Image(String webpFilepath, boolean png, String imageFilepath) throws IOException
      抛出:
      IOException
    • image2Webp

      public static void image2Webp(String imageFilepath, String webpFilepath) throws IOException
      抛出:
      IOException
    • image2Ico

      public static void image2Ico(InputStream input, String suffix, int size, String icoFilepath) throws IOException
      抛出:
      IOException
    • svgSafe

      public static boolean svgSafe(File imageFile) throws IOException
      抛出:
      IOException
    • thumb

      public static BufferedImage thumb(BufferedImage sourceImage, int width, int height, int angle, boolean png)
    • thumb

      public static void thumb(String sourceFilePath, String thumbFilePath, int width, int height, String suffix) throws IOException, com.drew.imaging.ImageProcessingException
      抛出:
      IOException
      com.drew.imaging.ImageProcessingException
    • getAngle

      public static int getAngle(File file) throws com.drew.imaging.ImageProcessingException, IOException
      抛出:
      com.drew.imaging.ImageProcessingException
      IOException
    • watermark

      public static void watermark(String sourceFilePath, String watermarkFilePath, String watermarkText, String color, String font, int fontsize, float alpha, String position, String suffix) throws IOException
      抛出:
      IOException
    • matermarkPosition

      private static int matermarkPosition(String position, int width, int height, int watermarkWidth, int watermarkHeight, int textWidth, int textHeight, boolean x, boolean text)