类 ImageUtils
java.lang.Object
com.publiccms.common.tools.ImageUtils
ImageUtils
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static void
drawImage
(int width, int height, String text, OutputStream outputStream) @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); }static String
generateImageData
(int width, int height, String text) static int
private static Font
getFont
(int size) private static Color
getRandColor
(int fc, int bc) static void
image2Ico
(InputStream input, String suffix, int size, String icoFilepath) static void
image2Webp
(String imageFilepath, String webpFilepath) private static int
matermarkPosition
(String position, int width, int height, int watermarkWidth, int watermarkHeight, int textWidth, int textHeight, boolean x, boolean text) private static void
static boolean
static BufferedImage
thumb
(BufferedImage sourceImage, int width, int height, int angle, boolean png) static void
static void
watermark
(String sourceFilePath, String watermarkFilePath, String watermarkText, String color, String font, int fontsize, float alpha, String position, String suffix) static void
webp2Image
(InputStream webpInputStream, boolean png, String imageFilepath) static void
webp2Image
(String webpFilepath, boolean png, String imageFilepath)
-
字段详细资料
-
log
private static final org.apache.commons.logging.Log log -
FORMAT_NAME_PNG
- 另请参阅:
-
FORMAT_NAME_JPG
- 另请参阅:
-
FORMAT_NAME_WEBP
- 另请参阅:
-
FORMAT_NAME_SVG
- 另请参阅:
-
DEFAULT_FORMAT_NAME
- 另请参阅:
-
-
构造器详细资料
-
ImageUtils
private ImageUtils()
-
-
方法详细资料
-
generateImageData
- 参数:
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
-
getRandColor
-
getFont
-
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
- 抛出:
IOException
-
image2Ico
public static void image2Ico(InputStream input, String suffix, int size, String icoFilepath) throws IOException - 抛出:
IOException
-
svgSafe
- 抛出:
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
- 抛出:
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)
-