@Test public void scaleImage() { String sourceFilePath = getImageFullPath("01.jpg"); Map<String, String> imageBaseInfo = ImageUtil.getImageBasicInfo(sourceFilePath); String destFilePath = sourceFilePath + "_scale_" + sourceFilePath.substring(sourceFilePath.lastIndexOf('.')); int width = Integer.parseInt(imageBaseInfo.get(ImageUtil.IMAGE_WIDTH)) / 2; int height = Integer.parseInt(imageBaseInfo.get(ImageUtil.IMAGE_HEIGHT)) / 2; boolean success = ImageUtil.scaleImage(sourceFilePath, width, height, destFilePath, 80d); Assert.assertTrue(success); boolean delete = new File(destFilePath).delete(); Assert.assertTrue(delete); }
public static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath, Double quality) { Assert.assertNotNull(sourceImage, "图片缩放的图片源不能为空"); Assert.assertNotBlank(destFilePath, "图片缩放的目标存储位置不能为空"); Assert.assertPositive(width, "图片缩放的期望宽度不能小于0"); Assert.assertPositive(height, "图片缩放的期望高度不能小于0"); ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(); op.resize(width, height); op.addImage(); try { convert.run(op, sourceImage, destFilePath); return true; } catch (Exception e) { return false; } }
ImageUtil implements ItemImageCons { public static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath, Double quality) { Assert.assertNotNull(sourceImage, "图片缩放的图片源不能为空"); Assert.assertNotBlank(destFilePath, "图片缩放的目标存储位置不能为空"); Assert.assertPositive(width, "图片缩放的期望宽度不能小于0"); Assert.assertPositive(height, "图片缩放的期望高度不能小于0"); ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(); op.resize(width, height); op.addImage(); try { convert.run(op, sourceImage, destFilePath); return true; } catch (Exception e) { return false; } } }
ImageUtil implements ItemImageCons { public static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath, Double quality) { Assert.assertNotNull(sourceImage, "图片缩放的图片源不能为空"); Assert.assertNotBlank(destFilePath, "图片缩放的目标存储位置不能为空"); Assert.assertPositive(width, "图片缩放的期望宽度不能小于0"); Assert.assertPositive(height, "图片缩放的期望高度不能小于0"); ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(); op.resize(width, height); op.addImage(); try { convert.run(op, sourceImage, destFilePath); return true; } catch (Exception e) { return false; } }  }
ImageUtil implements ItemImageCons { public static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath, Double quality) { Assert.assertNotNull(sourceImage, "图片缩放的图片源不能为空"); Assert.assertNotBlank(destFilePath, "图片缩放的目标存储位置不能为空"); Assert.assertPositive(width, "图片缩放的期望宽度不能小于0"); Assert.assertPositive(height, "图片缩放的期望高度不能小于0"); ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(); op.resize(width, height); op.addImage(); try { convert.run(op, sourceImage, destFilePath); return true; } catch (Exception e) { return false; } }  static boolean isDebugMode(); static Info getImageInfo(String imgFile); static String getProperty(Info imageInfo, String propertyName); static Map<String, String> getImageBasicInfo(String imageFilePath); static Map<String, Integer> getImageWH(String imageFilePath); static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight); static boolean cutAndScaleImage(String sourceFilePath, String destFilePath, Double quality, int xOffset,
                                           int yOffset, int width, int height, int scaleWidth, int scaleHeight); static boolean cutImage(String sourceFilePath, String destFilePath, Double quality, int xOffset,
                                   int yOffset, int width, int height); static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath,
                                     Double quality); static boolean scaleImage(String sourceFilePath, int width, int height, String destFilePath, Double quality); static String compositImage(String imageSavePath, ImageFormat format, String bgImage, String iconImage,
                                       GravityEnum position, Integer x, Integer y, Integer width, Integer height,
                                       Double rotation); static String compositImage(String imageSavePath, ImageFormat format, String bgImage, String iconImage,
                                       GravityEnum position, Integer x, Integer y, Integer width, Integer height,
                                       Double rotation, boolean deleteIconFile, Double quality); static String drawCircleWithText(String imageSavePath, String text, String textColor, String fontName,
                                            Integer fontSize, String circleFillColor, String circleStrokeColor,
                                            Integer circleStrokeWidth, Integer x, Integer y, Integer w, Double rotation); static String drawRectangleWithText(String imageSavePath, String text, String textColor, String fontName,
                                               Integer fontSize, String rectFillColor, String rectStrokeColor,
                                               Integer rectStrokeWidth, Integer x, Integer y, Integer w, Integer h,
                                               Double rotation); static String createTextImage(String text, boolean autoWrapper, String fontName, Integer fontSize,
                                         String textColor, Double rotation); static String drawRectangle(Integer x, Integer y, Integer w, Integer h, Integer round, String fillColor,
                                       String strokeColor, Integer strokeWidth, Double rotation); static String drawCircle(Integer width, Integer height, String fillColor, String strokeColor,
                                    Integer strokeWidth, Integer x, Integer y, Integer w, Double rotation); static String rotateImage(String originalImagePath, Double rotation); static String _rotateImage(String originalImagePath, Double rotation); static String drawEclipse(String fillColor, String strokeColor, Integer strokeWidth, Integer x, Integer y,
                                     Integer w, Integer h, Double rotation); static String borderImage(String srcImage, int borderWidth, String color); static String drawText(String text, GravityEnum gravity, String fontName, Integer fontSize,
                                  String textColor, String bgColor, Integer width, Integer height, Double rotation); static String autoResize(String srcImagePath); static String autoResize(String srcImagePath, String destImagePath); }
ImageUtil implements ItemImageCons { public static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath, Double quality) { Assert.assertNotNull(sourceImage, "图片缩放的图片源不能为空"); Assert.assertNotBlank(destFilePath, "图片缩放的目标存储位置不能为空"); Assert.assertPositive(width, "图片缩放的期望宽度不能小于0"); Assert.assertPositive(height, "图片缩放的期望高度不能小于0"); ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(); op.resize(width, height); op.addImage(); try { convert.run(op, sourceImage, destFilePath); return true; } catch (Exception e) { return false; } }  static boolean isDebugMode(); static Info getImageInfo(String imgFile); static String getProperty(Info imageInfo, String propertyName); static Map<String, String> getImageBasicInfo(String imageFilePath); static Map<String, Integer> getImageWH(String imageFilePath); static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight); static boolean cutAndScaleImage(String sourceFilePath, String destFilePath, Double quality, int xOffset,
                                           int yOffset, int width, int height, int scaleWidth, int scaleHeight); static boolean cutImage(String sourceFilePath, String destFilePath, Double quality, int xOffset,
                                   int yOffset, int width, int height); static boolean scaleImage(BufferedImage sourceImage, int width, int height, String destFilePath,
                                     Double quality); static boolean scaleImage(String sourceFilePath, int width, int height, String destFilePath, Double quality); static String compositImage(String imageSavePath, ImageFormat format, String bgImage, String iconImage,
                                       GravityEnum position, Integer x, Integer y, Integer width, Integer height,
                                       Double rotation); static String compositImage(String imageSavePath, ImageFormat format, String bgImage, String iconImage,
                                       GravityEnum position, Integer x, Integer y, Integer width, Integer height,
                                       Double rotation, boolean deleteIconFile, Double quality); static String drawCircleWithText(String imageSavePath, String text, String textColor, String fontName,
                                            Integer fontSize, String circleFillColor, String circleStrokeColor,
                                            Integer circleStrokeWidth, Integer x, Integer y, Integer w, Double rotation); static String drawRectangleWithText(String imageSavePath, String text, String textColor, String fontName,
                                               Integer fontSize, String rectFillColor, String rectStrokeColor,
                                               Integer rectStrokeWidth, Integer x, Integer y, Integer w, Integer h,
                                               Double rotation); static String createTextImage(String text, boolean autoWrapper, String fontName, Integer fontSize,
                                         String textColor, Double rotation); static String drawRectangle(Integer x, Integer y, Integer w, Integer h, Integer round, String fillColor,
                                       String strokeColor, Integer strokeWidth, Double rotation); static String drawCircle(Integer width, Integer height, String fillColor, String strokeColor,
                                    Integer strokeWidth, Integer x, Integer y, Integer w, Double rotation); static String rotateImage(String originalImagePath, Double rotation); static String _rotateImage(String originalImagePath, Double rotation); static String drawEclipse(String fillColor, String strokeColor, Integer strokeWidth, Integer x, Integer y,
                                     Integer w, Integer h, Double rotation); static String borderImage(String srcImage, int borderWidth, String color); static String drawText(String text, GravityEnum gravity, String fontName, Integer fontSize,
                                  String textColor, String bgColor, Integer width, Integer height, Double rotation); static String autoResize(String srcImagePath); static String autoResize(String srcImagePath, String destImagePath); static final String IMAGE_QUALITY; static final String IMAGE_HEIGHT; static final String IMAGE_WIDTH; static final String IMAGE_FORMAT; static final boolean isDebug; }