当前位置: 首页>>代码示例>>Java>>正文


Java ConvertCmd类代码示例

本文整理汇总了Java中org.im4java.core.ConvertCmd的典型用法代码示例。如果您正苦于以下问题:Java ConvertCmd类的具体用法?Java ConvertCmd怎么用?Java ConvertCmd使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConvertCmd类属于org.im4java.core包,在下文中一共展示了ConvertCmd类的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);
	} 
	
	
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:27,代码来源:ImageRotator.java

示例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);
	}
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:18,代码来源:ThumbnailPNGCreator.java

示例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);

}
 
开发者ID:lklong,项目名称:imageweb,代码行数:17,代码来源:ImageUtilTest.java

示例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();
}
 
开发者ID:exc-asia-and-europe,项目名称:imagemagick.xq,代码行数:26,代码来源:ConvertFunction.java

示例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();
}
 
开发者ID:exc-asia-and-europe,项目名称:imagemagick.xq,代码行数:18,代码来源:Convert.java

示例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();
}
 
开发者ID:exc-asia-and-europe,项目名称:imagemagick.xq,代码行数:24,代码来源:Convert.java

示例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();
}
 
开发者ID:exc-asia-and-europe,项目名称:imagemagick.xq,代码行数:22,代码来源:Convert.java

示例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();
}
 
开发者ID:exc-asia-and-europe,项目名称:imagemagick.xq,代码行数:19,代码来源:Convert.java

示例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;
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:29,代码来源:ImageUtils.java

示例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;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:44,代码来源:MultiPageExecutor.java

示例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);
}
 
开发者ID:saikrishna321,项目名称:AppiumTestDistribution,代码行数:14,代码来源:ImageUtils.java

示例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);

}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:78,代码来源:ImageOverlayCreator.java

示例13: MultiPageExecutor

import org.im4java.core.ConvertCmd; //导入依赖的package包/类
/**
 * This method creates multi page pdf using Image-Magick.
 * 
 * @param batchInstanceThread {@link BatchInstanceThread}
 * @param pages11 {@link String []}
 * @param pdfCompression {@link String}
 * @param pdfQuality {@link String}
 * @param coloredImage {@link String}
 * @param pdfOptimizationSwitch {@link String}
 */
public MultiPageExecutor(BatchInstanceThread batchInstanceThread, final String[] pages11, final String pdfCompression,
		final String pdfQuality, final String coloredImage, final String pdfOptimizationSwitch) {
	this.pages = new String[pages11.length];
	this.pages = pages11.clone();
	batchInstanceThread.add(new AbstractRunnable() {

		@Override
		public void run() {
			LOGGER.info("Creating multipgae pdf using imagemagick....");
			IMOperation imOper = new IMOperation();
			imOper.addImage(pages.length - 1);
			if (pdfQuality != null) {
				LOGGER.info("Adding pdfQuality : " + pdfQuality);
				imOper.quality(new Double(pdfQuality));
			}

			if (coloredImage != null && ImageMagicKConstants.FALSE.equalsIgnoreCase(coloredImage)) {
				imOper.monochrome();
			}
			if (pdfCompression != null) {
				LOGGER.info("Adding pdfCompression : " + pdfCompression);
				imOper.compress(pdfCompression);
			}

			if (pdfOptimizationSwitch != null && pdfOptimizationSwitch.equalsIgnoreCase(ImageMagicKConstants.ON_SWITCH)) {
				LOGGER.info("Adding pdfOptimnisation.");
				// As per Ike suggestion, not performing any optimization with Imagemagick using PDF
				// op.type("optimize");
			}

			imOper.addImage();
			ConvertCmd convert = new ConvertCmd();
			try {
				convert.run(imOper, (Object[]) pages);
			} catch (Exception e) {
				LOGGER.error(MULTIPAGE_PDF_CREATION_ERROR_MSG + e.getMessage(), e);
				setDcmaApplicationException(new DCMAApplicationException(MULTIPAGE_PDF_CREATION_ERROR_MSG + e.getMessage(), e));
			}
		}
	});
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:52,代码来源:MultiPageExecutor.java

示例14: 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;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:45,代码来源:SampleThumbnailGenerator.java

示例15: 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;
 }
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:52,代码来源:UserServiceImpl.java


注:本文中的org.im4java.core.ConvertCmd类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。