1 24 package org.riotfamily.common.image; 25 26 import java.io.File ; 27 import java.io.IOException ; 28 import java.util.ArrayList ; 29 30 import org.riotfamily.common.io.CommandUtils; 31 import org.springframework.util.StringUtils; 32 33 37 public class ImageMagickCropper implements ImageCropper { 38 39 private String convertCommand = "convert"; 40 41 private boolean repage = true; 42 43 public void setConvertCommand(String convertCommand) { 44 this.convertCommand = convertCommand; 45 } 46 47 52 public void setRepage(boolean repage) { 53 this.repage = repage; 54 } 55 56 public void cropImage(File source, File dest, int width, int height, 57 int x, int y, int scaledWidth) throws IOException { 58 59 ArrayList cmd = new ArrayList (); 60 cmd.add(convertCommand); 61 cmd.add(source.getAbsolutePath()); 62 cmd.add("-resize"); 63 cmd.add(scaledWidth + "x>"); 64 cmd.add("-crop"); 65 cmd.add(width + "x" + height + "+" + x + "+" + y); 66 if (repage) { 67 cmd.add("+repage"); 68 } 69 else { 70 cmd.add("-page"); 71 cmd.add("+0+0"); 72 } 73 cmd.add("-quality"); 74 cmd.add("100"); 75 76 cmd.add(dest.getAbsolutePath()); 77 CommandUtils.exec(StringUtils.toStringArray(cmd)); 78 } 79 80 } 81 | Popular Tags |