@Test public void splitImage() { String imageFilePath = getImageFullPath("01.jpg"); List<String> splitImage = ImageUtil.splitImage(new File(imageFilePath), 80d, -1, 60); Assert.assertTrue(splitImage.size() > 0); for (String fileName : splitImage) { boolean delete = new File(fileName).delete(); Assert.assertTrue(delete); } }
public static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight) { try { String srcFileName = srcFile.getPath(); int imgWidth; int imgHeight; try { Map<String, String> imageBasicInfo = getImageBasicInfo(srcFileName); imgWidth = Integer.parseInt(imageBasicInfo.get(IMAGE_WIDTH)); imgHeight = Integer.parseInt(imageBasicInfo.get(IMAGE_HEIGHT)); } catch (Exception e) { return Collections.emptyList(); } int col = 1; if (!(expectedWidth == null || expectedWidth == -1)) { col = imgWidth / expectedWidth; col = (col == 0 ? 1 : col); } int row = 1; if (!(expectedHeight == null || expectedHeight == -1)) { row = (imgHeight / expectedHeight); int left = imgHeight % expectedHeight; if (left > (expectedHeight / 2) && row > 0) { row++; } row = (row == 0 ? 1 : row); } ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(srcFile.getPath()); op.crop(null, null, null, null, col + "x" + row + "@"); int index = srcFileName.lastIndexOf('.'); String prefix = srcFileName.substring(0, index); String suffix = srcFileName.substring(index); String destFileName = prefix + "_%d" + suffix; op.addImage(destFileName); convert.run(op); List<String> list = new ArrayList<String>(); for (int i = 0; i < row; i++) { list.add(prefix + "_" + i + suffix); } return list; } catch (Exception e) { return Collections.emptyList(); } }
ImageUtil implements ItemImageCons { public static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight) { try { String srcFileName = srcFile.getPath(); int imgWidth; int imgHeight; try { Map<String, String> imageBasicInfo = getImageBasicInfo(srcFileName); imgWidth = Integer.parseInt(imageBasicInfo.get(IMAGE_WIDTH)); imgHeight = Integer.parseInt(imageBasicInfo.get(IMAGE_HEIGHT)); } catch (Exception e) { return Collections.emptyList(); } int col = 1; if (!(expectedWidth == null || expectedWidth == -1)) { col = imgWidth / expectedWidth; col = (col == 0 ? 1 : col); } int row = 1; if (!(expectedHeight == null || expectedHeight == -1)) { row = (imgHeight / expectedHeight); int left = imgHeight % expectedHeight; if (left > (expectedHeight / 2) && row > 0) { row++; } row = (row == 0 ? 1 : row); } ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(srcFile.getPath()); op.crop(null, null, null, null, col + "x" + row + "@"); int index = srcFileName.lastIndexOf('.'); String prefix = srcFileName.substring(0, index); String suffix = srcFileName.substring(index); String destFileName = prefix + "_%d" + suffix; op.addImage(destFileName); convert.run(op); List<String> list = new ArrayList<String>(); for (int i = 0; i < row; i++) { list.add(prefix + "_" + i + suffix); } return list; } catch (Exception e) { return Collections.emptyList(); } } }
ImageUtil implements ItemImageCons { public static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight) { try { String srcFileName = srcFile.getPath(); int imgWidth; int imgHeight; try { Map<String, String> imageBasicInfo = getImageBasicInfo(srcFileName); imgWidth = Integer.parseInt(imageBasicInfo.get(IMAGE_WIDTH)); imgHeight = Integer.parseInt(imageBasicInfo.get(IMAGE_HEIGHT)); } catch (Exception e) { return Collections.emptyList(); } int col = 1; if (!(expectedWidth == null || expectedWidth == -1)) { col = imgWidth / expectedWidth; col = (col == 0 ? 1 : col); } int row = 1; if (!(expectedHeight == null || expectedHeight == -1)) { row = (imgHeight / expectedHeight); int left = imgHeight % expectedHeight; if (left > (expectedHeight / 2) && row > 0) { row++; } row = (row == 0 ? 1 : row); } ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(srcFile.getPath()); op.crop(null, null, null, null, col + "x" + row + "@"); int index = srcFileName.lastIndexOf('.'); String prefix = srcFileName.substring(0, index); String suffix = srcFileName.substring(index); String destFileName = prefix + "_%d" + suffix; op.addImage(destFileName); convert.run(op); List<String> list = new ArrayList<String>(); for (int i = 0; i < row; i++) { list.add(prefix + "_" + i + suffix); } return list; } catch (Exception e) { return Collections.emptyList(); } }  }
ImageUtil implements ItemImageCons { public static List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight) { try { String srcFileName = srcFile.getPath(); int imgWidth; int imgHeight; try { Map<String, String> imageBasicInfo = getImageBasicInfo(srcFileName); imgWidth = Integer.parseInt(imageBasicInfo.get(IMAGE_WIDTH)); imgHeight = Integer.parseInt(imageBasicInfo.get(IMAGE_HEIGHT)); } catch (Exception e) { return Collections.emptyList(); } int col = 1; if (!(expectedWidth == null || expectedWidth == -1)) { col = imgWidth / expectedWidth; col = (col == 0 ? 1 : col); } int row = 1; if (!(expectedHeight == null || expectedHeight == -1)) { row = (imgHeight / expectedHeight); int left = imgHeight % expectedHeight; if (left > (expectedHeight / 2) && row > 0) { row++; } row = (row == 0 ? 1 : row); } ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(srcFile.getPath()); op.crop(null, null, null, null, col + "x" + row + "@"); int index = srcFileName.lastIndexOf('.'); String prefix = srcFileName.substring(0, index); String suffix = srcFileName.substring(index); String destFileName = prefix + "_%d" + suffix; op.addImage(destFileName); convert.run(op); List<String> list = new ArrayList<String>(); for (int i = 0; i < row; i++) { list.add(prefix + "_" + i + suffix); } return list; } catch (Exception e) { return Collections.emptyList(); } }  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 List<String> splitImage(File srcFile, Double quality, Integer expectedWidth, Integer expectedHeight) { try { String srcFileName = srcFile.getPath(); int imgWidth; int imgHeight; try { Map<String, String> imageBasicInfo = getImageBasicInfo(srcFileName); imgWidth = Integer.parseInt(imageBasicInfo.get(IMAGE_WIDTH)); imgHeight = Integer.parseInt(imageBasicInfo.get(IMAGE_HEIGHT)); } catch (Exception e) { return Collections.emptyList(); } int col = 1; if (!(expectedWidth == null || expectedWidth == -1)) { col = imgWidth / expectedWidth; col = (col == 0 ? 1 : col); } int row = 1; if (!(expectedHeight == null || expectedHeight == -1)) { row = (imgHeight / expectedHeight); int left = imgHeight % expectedHeight; if (left > (expectedHeight / 2) && row > 0) { row++; } row = (row == 0 ? 1 : row); } ConvertCmd convert = new ConvertCmd(); IMOperation op = new IMOperation(); if (quality != null && quality > 0) { op.quality(quality); } op.addImage(srcFile.getPath()); op.crop(null, null, null, null, col + "x" + row + "@"); int index = srcFileName.lastIndexOf('.'); String prefix = srcFileName.substring(0, index); String suffix = srcFileName.substring(index); String destFileName = prefix + "_%d" + suffix; op.addImage(destFileName); convert.run(op); List<String> list = new ArrayList<String>(); for (int i = 0; i < row; i++) { list.add(prefix + "_" + i + suffix); } return list; } catch (Exception e) { return Collections.emptyList(); } }  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; }