本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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));
}
示例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));
}
示例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)));
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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);
}