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


Java IMOperation.resize方法代码示例

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


在下文中一共展示了IMOperation.resize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run_chokes_whenServiceChokes

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_chokes_whenServiceChokes() throws Exception {
    // create command
    final String command = "bad";
    sut = new GMBatchCommand(service, command);
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.addImage(SOURCE_IMAGE);
    op.resize(800, 600);
    op.addImage(TARGET_IMAGE);
    final String message = "bad command";
    when(service.execute(anyListOf(String.class))).thenThrow(new GMException(message));
    exception.expect(CommandException.class);
    exception.expectMessage(message);

    // execute the operation
    sut.run(op);
}
 
开发者ID:sharneng,项目名称:gm4java,代码行数:19,代码来源:GMBatchCommandTest.java

示例2: resize

import org.im4java.core.IMOperation; //导入方法依赖的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

示例3: run_chokes_whenErrorConsumerIsNull

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
@SuppressWarnings("NP_NONNULL_PARAM_VIOLATION")
public void run_chokes_whenErrorConsumerIsNull() throws Exception {
    // create command
    final String command = "bad";
    sut = new GMBatchCommand(service, command);
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.addImage(SOURCE_IMAGE);
    op.resize(800, 600);
    op.addImage(TARGET_IMAGE);
    final String message = "bad command";
    when(service.execute(anyListOf(String.class))).thenThrow(new GMException(message));
    exception.expect(CommandException.class);
    exception.expectMessage(message);
    sut.setErrorConsumer(null);

    // execute the operation
    sut.run(op);
}
 
开发者ID:sharneng,项目名称:gm4java,代码行数:21,代码来源:GMBatchCommandTest.java

示例4: run_sendsCommandToService

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_sendsCommandToService() throws Exception {
    // create command
    final String command = "convert";
    sut = new GMBatchCommand(service, command);
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.addImage(SOURCE_IMAGE);
    op.resize(800, 600);
    op.addImage(TARGET_IMAGE);

    // execute the operation
    sut.run(op);

    verify(service).execute(Arrays.asList(command, SOURCE_IMAGE, "-resize", "800x600", TARGET_IMAGE));
}
 
开发者ID:sharneng,项目名称:gm4java,代码行数:17,代码来源:GMBatchCommandTest.java

示例5: run_works_whenOutputConsumerIsNull

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
@SuppressWarnings("NP_NONNULL_PARAM_VIOLATION")
public void run_works_whenOutputConsumerIsNull() throws Exception {
    // create command
    final String command = "convert";
    sut = new GMBatchCommand(service, command);
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.addImage(SOURCE_IMAGE);
    op.resize(800, 600);
    op.addImage(TARGET_IMAGE);
    sut.setOutputConsumer(null);

    // execute the operation
    sut.run(op);

    verify(service).execute(Arrays.asList(command, SOURCE_IMAGE, "-resize", "800x600", TARGET_IMAGE));
}
 
开发者ID:sharneng,项目名称:gm4java,代码行数:19,代码来源:GMBatchCommandTest.java

示例6: run_handlesBufferedImageAsInput

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_handlesBufferedImageAsInput() throws Exception {
    final String command = "convert";
    sut = new GMBatchCommand(service, command);
    BufferedImage image = ImageIO.read(getClass().getResourceAsStream("/a.png"));
    IMOperation op = new IMOperation();
    op.addImage();                        // input
    op.resize(80, 60);
    op.addImage();                        // output

    sut.run(op, image, TARGET_IMAGE);

    @java.lang.SuppressWarnings("unchecked")
    ArgumentCaptor<List<String>> captor = ArgumentCaptor.forClass((Class<List<String>>) (Class<?>) List.class);
    verify(service).execute(captor.capture());
    assertThat(captor.getValue(),
            equalTo(Arrays.asList(command, captor.getValue().get(1), "-resize", "80x60", TARGET_IMAGE)));
}
 
开发者ID:sharneng,项目名称:gm4java,代码行数:19,代码来源:GMBatchCommandTest.java

示例7: process

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Override
public final Image process(final Image image) throws Exception {

	String imageFileName = imageDirectory + File.separatorChar  + image.getId() + '.' + image.getFormat();
	File file = new File(imageFileName);
	if(!file.exists()) {
		logger.warn("File does not exist in image directory, skipping");
		imageAnnotator.annotate(image, AnnotationType.Error, AnnotationCode.BadData, "The local file was not found, so cannot be resized");
	} else {
		try {
			ImageInfo imageInfo = Sanselan.getImageInfo(file);
			Integer width = new Integer(imageInfo.getWidth());
			Integer height = new Integer(imageInfo.getHeight());
			logger.debug("Image " + imageFileName + " dimensions: " + width + " x " + height);

			if (width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION) {

				// shrink to no larger than MAX_IMAGE_DIMENSION * MAX_IMAGE_DIMENSION
				MogrifyCmd mogrify = new MogrifyCmd();
				if (searchPath != null) {
					mogrify.setSearchPath(searchPath);
				}
				IMOperation resize = new IMOperation();
				resize.addImage(imageFileName);
				logger.debug("resizing to no larger than " + MAX_IMAGE_DIMENSION.intValue()  + " * " + MAX_IMAGE_DIMENSION.intValue());
				resize.resize(MAX_IMAGE_DIMENSION.intValue(), MAX_IMAGE_DIMENSION.intValue(),'>');
				resize.addImage(imageFileName);
				mogrify.run(resize);

			} else {
				logger.info("No need to resize image as it is smaller than " + MAX_IMAGE_DIMENSION + "px x " + MAX_IMAGE_DIMENSION + "px");
			}
		} catch (Exception e) {
			logger.error("There was an error resizing the image", e);
			imageAnnotator.annotate(image, AnnotationType.Error, AnnotationCode.BadData, "The file could not be resized");
		}
	}
	return image;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:40,代码来源:ImageResizerImpl.java

示例8: makeProfileThumbnail

import org.im4java.core.IMOperation; //导入方法依赖的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

示例9: thumbnail

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
 * Creates a thumbnail from the source image specified to the specified
 * location with the given width and height. Width and height are used as
 * provided, so aspect ratio in resulting image may vary from original.
 * 
 * @param originPath
 *            Path to the source image to make a thumbnail for. Can be a
 *            relative or absolute path, as long as it can be resolved.
 *            E.g.: "big_image.png", "C:/images/big_image.png"
 * @param outputPath
 *            Path to the location to store the thumbnail. Can be a relative
 *            or absolute path, as long as it can be resolved. E.g.:
 *            "thumbnail_image.png", "C:/images/thumbnail_image.png"
 * @param width
 *            The width of the output image, in pixels
 * @param height
 *            The height of the output image, in pixels.
 */
public void thumbnail(String originPath, String outputPath, int width,
		int height) {
	IMOperation op = new IMOperation();
	if (originPath.toLowerCase().endsWith(".png")) {
		fillPNGOptions(op);
	}
	op.addImage(originPath);
	op.resize(width, height);
	op.addImage(outputPath);
	try {
		convertCmd.run(op);
	} catch (Exception e) {
		e.printStackTrace();
		System.err.println("[Error] Could not create thumbnail for "
				+ originPath);
	}
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:36,代码来源:ImgMagickUtils.java

示例10: resizeImage

import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
 * 图片压缩 严格按照指定规格压缩图片
 * 
 * @param width
 *            宽度
 * @param height
 *            高度
 * @param is
 * @param os
 * @throws IOException
 * @throws InterruptedException
 * @throws IM4JavaException
 *
 */
public static void resizeImage(Integer width, Integer height, Integer nWidth, Integer nHeight, BufferedImage img, String descPath) throws IOException, InterruptedException, IM4JavaException {

	if (nHeight >= height) {

		nHeight = height;

	}

	if (nWidth >= width) {

		nWidth = width;

	}

	IMOperation op = new IMOperation();
	
	op.addImage();

	op.resize(nWidth, nHeight, "!");
	
	//去掉图片所有内置信息
	op.addRawArgs("+profile","*");
	
	op.addRawArgs("-quality","90.0");

	op.addImage();
	
	ConvertCmd cmd = new ConvertCmd(GraphicImageConstants.GM);

	cmd.run(op,img,descPath);

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


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