本文整理汇总了Java中org.im4java.core.ConvertCmd.run方法的典型用法代码示例。如果您正苦于以下问题:Java ConvertCmd.run方法的具体用法?Java ConvertCmd.run怎么用?Java ConvertCmd.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.im4java.core.ConvertCmd
的用法示例。
在下文中一共展示了ConvertCmd.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotateImage
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
/**
* This method is used to rotate the image present at the image path given with default degree of rotation.
* @param imagePath {@link String}
* @param degreeOfRotation double
* @throws DCMAApplicationException if any exception occurs during rotation of image.
*/
public void rotateImage(String imagePath, double degreeOfRotation) throws DCMAApplicationException {
File fImagePath = new File(imagePath);
if(!fImagePath.exists()){
throw new DCMABusinessException("File does not exist filename="+fImagePath);
}
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operation = new IMOperation();
operation.rotate(degreeOfRotation);
operation.addImage();
operation.addImage();
Object[] listOfFiles = {imagePath,imagePath};
try {
convertcmd.run(operation, listOfFiles);
} catch (Exception e) {
LOGGER.error("Problem rotating image "+imagePath);
throw new DCMAApplicationException("Unable to rotate Image", e);
}
}
示例2: generatePNGForImage
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
public void generatePNGForImage(File imagePath) throws DCMAApplicationException {
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operationPNG = new IMOperation();
operationPNG.addImage();
operationPNG.addImage();
String imageName = imagePath.getAbsolutePath();
// TODO remove hard coding _thumb.png, .png and .tif
String pngPath = imageName.substring(0, imageName.lastIndexOf(ImageMagicKConstants.DOT));
try {
String[] listOfFiles = {imageName, pngPath + FileType.PNG.getExtensionWithDot()};
convertcmd.run(operationPNG, (Object[]) listOfFiles);
} catch (Exception ex) {
LOGGER.error("Problem generating png.");
throw new DCMAApplicationException("Problem generating png.", ex);
}
}
示例3: test_2
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
@Test
public void test_2() throws IOException, InterruptedException, IM4JavaException {
ConvertCmd cvcmd = new ConvertCmd(GM);
Operation op = new Operation();
op.addImage(PIC_PATH);
op.addRawArgs("-sample", "600x600^");
op.addRawArgs("-gravity", "center");
op.addRawArgs("-extent", "600x600");
op.addRawArgs("-quality", "100");
op.addImage(NEW_PIC_PATH);
cvcmd.run(op);
}
示例4: convertWithOptions
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
public byte[] convertWithOptions(InputStream image, String options) {
String[] optionStrings = options.split(" ");
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.addRawArgs(optionStrings);
iMOperation.addImage(":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
try {
convertCmd.run(iMOperation);
} catch (IOException | InterruptedException | IM4JavaException exception) {
System.err.println(exception.getMessage());
}
return byteArrayOutputStream.toByteArray();
}
示例5: convert2ImageFormat
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
public static byte[] convert2ImageFormat(InputStream image, String format) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.addImage( format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例6: resize
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
protected static byte[] resize(InputStream image, Integer maxWidth, Integer maxHeight, String format, boolean keepAspectRatio) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
if(!keepAspectRatio) {
iMOperation.resize(maxWidth, maxHeight, '!');
} else {
iMOperation.resize(maxWidth, maxHeight);
}
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例7: crop
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
static byte[] crop(InputStream image, int width, int height, int offsetX, int offsetY, String format, int rwidth, int rheight) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.crop(width, height, offsetX, offsetY);
iMOperation.repage(rwidth, rheight);
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例8: rotate
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
static byte[] rotate(InputStream image, double degrees, String format) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.rotate(degrees);
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例9: truncateImage
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
public static boolean truncateImage(String ori, String dest, int width, int height) throws IOException, InterruptedException, IM4JavaException {
File oriFile = new File(ori);
validate(oriFile, dest);
BufferedImage src = ImageIO.read(oriFile); // 读入文件
int w = src.getWidth();
int h = src.getHeight();
int min = Math.min(w, h);
int side = Math.min(width, height);
IMOperation op = new IMOperation();
op.addImage(ori);
if (w <= width && h <= height) {
// Don't do anything
} else if (min < side) {
op.gravity("center").extent(width, height);
} else {
op.resize(width, height, '^').gravity("center").extent(width, height);
}
op.addImage(dest);
ConvertCmd convert = new ConvertCmd(true);
convert.run(op);
return true;
}
示例10: getCompressedImage
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
/**
* The <code>getCompressedImage</code> method is used to compress passed image according to compression type LZW, quality 100 and
* convert image to monochrome i.e., black and white w.r.t isColoredImage passed.
*
* @param isColoredImage true for colored image and false otherwise
* @param imageUrl image to be converted
* @return url of converted image from passed image
*/
private String getCompressedImage(boolean isColoredImage, String imageUrl) {
String newImageUrl = imageUrl;
if (null != imageUrl && imageUrl.length() > 0) {
IMOperation imOperation = new IMOperation();
// Applying default image quality
imOperation.quality((double) IMAGE_QUALITY);
imOperation.type(OPERATION_TYPE);
if (!isColoredImage) {
imOperation.monochrome();
}
// Apply compression
imOperation.compress(COMPRESSION_TYPE);
imOperation.addImage(); // place holder for input file
imOperation.addImage(); // place holder for output file
// Converting image
ConvertCmd convert = new ConvertCmd();
newImageUrl = imageUrl.substring(0, imageUrl.lastIndexOf(DOTS)) + NEW + TIF_EXTENSION;
try {
convert.run(imOperation, new Object[] {imageUrl, newImageUrl});
} catch (org.im4java.core.CommandException commandException) {
LOGGER.error("IM4JAVA_TOOLPATH is not set for converting images using image magic: " + commandException.toString());
} catch (IOException ioException) {
LOGGER.error("Files not found for converting operation of image magic: " + ioException.toString());
} catch (InterruptedException interruptedException) {
LOGGER.error("Conversion operation of image magic interrupted in between: " + interruptedException.toString());
} catch (IM4JavaException im4JavaException) {
LOGGER.error("Error occurred while converting images using image magic: " + im4JavaException.toString());
}
}
return newImageUrl;
}
示例11: wrapDeviceFrames
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
public void wrapDeviceFrames(String deviceFrame, String deviceScreenToBeFramed,
String framedDeviceScreen)
throws InterruptedException, IOException, IM4JavaException {
IMOperation op = new IMOperation();
op.addImage(deviceFrame);
op.addImage(deviceScreenToBeFramed);
op.gravity("center");
op.composite();
op.opaque("none");
op.addImage(framedDeviceScreen);
ConvertCmd cmd = new ConvertCmd();
cmd.run(op);
}
示例12: generateOverlayImages
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
/**
* This method takes bath folder path, batch id as Input and generates overlayed images.
*
* @param sBatchFolder
* @param batchInstanceIdentifier
* @throws JAXBException
* @throws DCMAApplicationException
*/
public void generateOverlayImages(String sBatchFolder, String batchInstanceIdentifier, BatchSchemaService batchSchemaService)
throws JAXBException, DCMAApplicationException {
Batch batch = batchSchemaService.getBatch(batchInstanceIdentifier);
File fBatchFolder = new File(sBatchFolder);
if (!fBatchFolder.exists() || !fBatchFolder.isDirectory()) {
throw new DCMABusinessException("Improper Folder Specified folder name->" + sBatchFolder);
}
LOGGER.info("Finding xml file for Overlyed Images generation in the folder--> " + fBatchFolder);
LOGGER.info("xml file parsed sucsessfully");
List<OverlayDetails> listOfOverlayDetails = getListOfOverlayedFiles(sBatchFolder, batch, batchInstanceIdentifier);
StringBuffer sbParameter = new StringBuffer();
for (int index = 0; index < listOfOverlayDetails.size(); index++) {
OverlayDetails overlayDetails = null;
try {
overlayDetails = listOfOverlayDetails.get(index);
if (overlayDetails.getFieldValue() == null || overlayDetails.getFieldValue().isEmpty()
|| overlayDetails.getCoordinatesList().getCoordinates().isEmpty()) {
continue;
}
List<Coordinates> coordinatesList = overlayDetails.getCoordinatesList().getCoordinates();
for (Coordinates coordinates : coordinatesList) {
if (coordinates.getX0() == null || coordinates.getX1() == null || coordinates.getY0() == null
|| coordinates.getY1() == null) {
continue;
}
String ocrFilePath = overlayDetails.getOcrFilePath();
String overlayFilePath = overlayDetails.getOverlayedFilePath();
Object[] listOfFiles = {ocrFilePath, overlayFilePath};
sbParameter.append("rectangle");
sbParameter.append(ImageMagicKConstants.SPACE);
sbParameter.append(coordinates.getX0());
sbParameter.append(ImageMagicKConstants.COMMA);
sbParameter.append(coordinates.getY0());
sbParameter.append(ImageMagicKConstants.COMMA);
sbParameter.append(coordinates.getX1());
sbParameter.append(ImageMagicKConstants.COMMA);
sbParameter.append(coordinates.getY1());
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operation = new IMOperation();
operation.addImage();
operation.fill("#0AFA");
String paramerter = sbParameter.toString();
sbParameter.delete(0, sbParameter.length());
LOGGER.info("Overlaying image " + ocrFilePath + " Overlay coordinates=" + paramerter + "Overlayed Image="
+ overlayFilePath);
operation.draw(paramerter);
operation.addImage();
convertcmd.run(operation, listOfFiles);
addFileToBatchSchema(batch, overlayDetails);
}
} catch (Exception ex) {
LOGGER.error("Problem generating Overlayed Image ");
// parsedXmlFile.setBatchStatus(BatchStatusType.ERROR);
// xmlReader.writeXML(BATCH_XSD_SCHEMA_PACKAGE, parsedXmlFile,
// xmlFile);
}
}
LOGGER.info("Overlayed Image generation complete for batch folder" + sBatchFolder + " persisitng info to xml file");
batchSchemaService.updateBatch(batch);
}
示例13: generateThumbnailsForFolder
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
private int generateThumbnailsForFolder(final String pageFolderPath) throws DCMAApplicationException {
int numberOfThumbnailsGenerated = 0;
File pageDirectory = new File(pageFolderPath);
String[] listOfPageFiles = pageDirectory.list(new CustomFileFilter(false, FileType.TIF.getExtensionWithDot(),
FileType.TIFF.getExtensionWithDot()));
StringBuffer pageFilepath;
StringBuffer thumbnailFilePath;
for (String pageFileName : listOfPageFiles) {
pageFilepath = new StringBuffer();
thumbnailFilePath = new StringBuffer();
pageFilepath.append(pageFolderPath).append(File.separator).append(pageFileName);
thumbnailFilePath.append(pageFolderPath);
thumbnailFilePath.append(File.separator);
thumbnailFilePath.append(IImageMagickCommonConstants.THUMBS);
thumbnailFilePath.append(File.separator);
thumbnailFilePath.append(pageFileName);
if (thumbnailType.equals(IImageMagickCommonConstants.EXT_TIF)) {
thumbnailFilePath.append(IImageMagickCommonConstants.SUFFIX_THUMBNAIL_SAMPLE_TIF);
}
if (thumbnailType.equals(IImageMagickCommonConstants.EXT_PNG)) {
thumbnailFilePath.append(IImageMagickCommonConstants.SUFFIX_THUMBNAIL_SAMPLE_PNG);
}
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operation = new IMOperation();
operation.addImage();
operation.thumbnail(Integer.parseInt(thumbnailH.trim()), Integer.parseInt(thumbnailW.trim()));
operation.addImage();
try {
String[] listOfFiles = {pageFilepath.toString(), thumbnailFilePath.toString()};
convertcmd.run(operation, (Object[]) listOfFiles);
LOGGER.info("***************Thumbnail generation of file " + pageFileName + " success");
numberOfThumbnailsGenerated++;
} catch (Exception ex) {
LOGGER.info("***************Thumbnail generation of file " + pageFileName + " Failiure");
LOGGER.error("Problem generating thumbnails for the File " + pageFilepath);
throw new DCMAApplicationException("Problem generating thumbnails", ex);
}
}
return numberOfThumbnailsGenerated;
}
示例14: makeProfileThumbnail
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
@Override
public String makeProfileThumbnail(MultipartFile file, String oldProfileImage) throws IOException, InterruptedException, IM4JavaException {
if(file != null && !file.isEmpty()) {
String tmpFileExtension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
String tmpFileName = UUID.randomUUID().toString() + tmpFileExtension;
File tmpFile = new File(temporaryFolder.getFile(),tmpFileName);
file.transferTo(tmpFile);
Metadata metadata = new Metadata();
AutoDetectParser parser = new AutoDetectParser();
FileInputStream fileInputStream = new FileInputStream(tmpFile);
String mimeType = tika.detect(fileInputStream);
String fileExtension = null;
switch(mimeType) {
case "image/jpeg":
fileExtension = ".jpg";
break;
case "image/png":
fileExtension = ".png";
break;
case "image/gif":
fileExtension = ".gif";
break;
default:
throw new UnsupportedOperationException(mimeType);
}
String imageFileName = UUID.randomUUID().toString() + fileExtension;
File imageFile = new File(userProfilesFolder.getFile(), imageFileName);
ConvertCmd convert = new ConvertCmd();
if (searchPath != null) {
convert.setSearchPath(searchPath);
}
IMOperation operation = new IMOperation();
operation.addImage(tmpFile.getAbsolutePath());
operation.resize(THUMBNAIL_DIMENSION.intValue(), THUMBNAIL_DIMENSION.intValue(), "^");
operation.gravity("center");
operation.extent(THUMBNAIL_DIMENSION.intValue(), THUMBNAIL_DIMENSION.intValue());
operation.addImage(imageFile.getAbsolutePath());
convert.run(operation);
tmpFile.delete();
if(oldProfileImage != null) {
File oldFile = new File(userProfilesFolder.getFile(),oldProfileImage);
oldFile.delete();
}
return imageFileName;
} else {
return null;
}
}
示例15: cropImageCenter
import org.im4java.core.ConvertCmd; //导入方法依赖的package包/类
/**
* 头像处理 先压缩再裁剪
*
* @param is
* @param os
* @param rectw
* @param recth
* @throws IOException
* @throws InterruptedException
* @throws IM4JavaException
*
*/
public static void cropImageCenter(BufferedImage img, String descPath, int rectw, int recth) throws IOException, InterruptedException, IM4JavaException {
IMOperation op = new IMOperation();
op.addImage();
op.resize(rectw, recth, '^').gravity("center").extent(rectw, recth).quality(100d);
//去掉图片所有内置信息
op.addRawArgs("+profile","*");
op.addRawArgs("-quality","90.0");
op.addImage();
ConvertCmd cmd = new ConvertCmd(GraphicImageConstants.GM);
cmd.run(op,img,descPath);
}