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


Java Builder类代码示例

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


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

示例1: compressTo

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
public String compressTo(String imagePath, String targetPath){
	if(!isCompressFile(imagePath)){
		throw new BaseException("not support compress file type: " + FileUtils.getExtendName(imagePath));
	}
	Builder<File> builder = Thumbnails.fromFilenames(Arrays.asList(imagePath));
	configBuilder(builder, config);
	
	File targetFile = null;
	if(StringUtils.isBlank(targetPath)){
		File imageFile = new File(imagePath);
		String fileName = FileUtils.getFileNameWithoutExt(imageFile.getName()) + "-compress" + FileUtils.getExtendName(imageFile.getName(), true);
		fileName = FileUtils.newFileNameAppendRepeatCount(imageFile.getParent(), fileName);
		targetFile = new File(imageFile.getParentFile(), fileName);
	}else{
		targetFile = new File(targetPath);
	}
	try {
		builder.toFile(targetFile);
	} catch (IOException e) {
		throw new BaseException("compress image error: " + e.getMessage(), e);
	}
	return targetPath;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:24,代码来源:ImageCompressor.java

示例2: configBuilder

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
/***
 * 
 * @author wayshall
 * @param builder
 */
protected void configBuilder(Builder<?> builder, ImageCompressorConfig config){
	if(config==null){
		return ;
	}
	if(config.getScale()!=null){
		builder.scale(config.getScale());//经过测试,可以大幅减少大小,比如 0.5
	}
	if(config.getWidth()!=null && config.getHeight()!=null){
		builder.size(config.getWidth(), config.getHeight());
	}else if(config.getWidth()!=null){
		builder.width(config.getWidth());
	}else if(config.getHeight()!=null){
		builder.height(config.getHeight());
	}
	if(config.getQuality()!=null){
		builder.outputQuality(config.getQuality());//压缩质量,比如 0.3,太低会影响质量,变成色块
	}
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:24,代码来源:ImageCompressor.java

示例3: main

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
public static void main(String[] args) {
	String filePath = "D:\\tomca7\\webapps\\unique-img-plugin\\upload\\12674158787444.jpg";
	File img = new File("D:\\tomca7\\webapps\\unique-img-plugin\\upload\\12674158787444_1.jpg");
	Builder<File> f = Thumbnails.of(filePath);
	f.size(200, 200);
	// f = f.scale(1);
	// f = f.outputQuality(quality);
	if ("a".equals("a")) {
		f.rotate(180);
	}
	try {
		f.toFile(img);
	} catch (IOException e) {
		logger.warn(e.getMessage());
	}
}
 
开发者ID:Wccczy,项目名称:Student_Register,代码行数:17,代码来源:ThumbExec.java

示例4: putWaterMark

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
private void putWaterMark(File file,Metadata metadata) throws IOException {
	
	BufferedImage bufferedImage = ImageIO.read(file);
	
	// Set up the caption properties
	String caption = "RASCUNHO";
	Font font = new Font("Monospaced", Font.PLAIN, 100);
	Color c = Color.GRAY;
	float opacity = 0.6f;
	Position[] positions = {Positions.TOP_LEFT,Positions.CENTER,Positions.BOTTOM_RIGHT};
	int insetPixels = 0;

	// Apply caption to the image
	Builder<BufferedImage> builder = Thumbnails.of(bufferedImage).size(bufferedImage.getHeight(),bufferedImage.getWidth()).outputFormat(metadata.getFileExtension());
	
	for(Position position: positions) {
		builder.addFilter(new Caption(caption, font, c, opacity, position, insetPixels));
	}
	BufferedImage result = builder.asBufferedImage();
	
	ImageIO.write(result, metadata.getFileExtension(), file);
}
 
开发者ID:josecoelho,项目名称:yep-rest-file-server,代码行数:23,代码来源:FileService.java

示例5: doResize

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
public static void doResize(File src, File dst, Integer width, Integer height, Double ratio) {
	try {
		Builder<File> builder = Thumbnails.of(src);
		if((width == null || height == null) && ratio != null){
			builder.scale(ratio).toFile(dst);
		}
		if((width !=null && height!=null) && ratio == null){
			builder.size(width, height).toFile(dst);
		}
		
	} catch (IOException e) {
		System.out.println("Error");
		System.out.println("src:"+src.toString());
		System.out.println("dst:"+dst.toString());
	}
}
 
开发者ID:kouhin,项目名称:thumbnail,代码行数:17,代码来源:Thumbnail.java

示例6: main

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
public static void main(String[] args) {
    String filePath = "D:\\tomca7\\webapps\\unique-img-plugin\\upload\\12674158787444.jpg";
    File img = new File("D:\\tomca7\\webapps\\unique-img-plugin\\upload\\12674158787444_1.jpg");
    Builder<File> f = Thumbnails.of(filePath);
    f.size(200, 200);
    // f = f.scale(1);
    // f = f.outputQuality(quality);
    if("a".equals("a")){
        f.rotate(180);
    }
    try {
        f.toFile(img);
    } catch (IOException e) {
        logger.warn(e.getMessage());
    }
}
 
开发者ID:mattxia,项目名称:unique-web,代码行数:17,代码来源:ThumbExec.java

示例7: resize

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
@SneakyThrows
private static byte[] resize(byte[] imageData, String targetFormat, int width, int height,
		boolean crop, float qualityFactor, double qualityMultiplicator) {
	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	Builder<? extends InputStream> builder = Thumbnails
		.of(new ByteArrayInputStream(imageData))
		.outputQuality(qualityFactor)
		.size(
			(int) Math.round(width * qualityMultiplicator),
			(int) Math.round(height * qualityMultiplicator)
		);

	if(crop) {
		builder.crop(Positions.CENTER);
	}

	try {
		builder
			.outputFormat(targetFormat)
			.toOutputStream(byteArrayOutputStream);
	} catch (IOException e) {
		logger.error("Cannot resize image to format {}", targetFormat, e);
		return null;
	}

	return byteArrayOutputStream.toByteArray();
}
 
开发者ID:Coreoz,项目名称:PPT-Templates,代码行数:28,代码来源:ImagesUtils.java

示例8: compressStream

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
public InputStream compressStream(InputStream imageInputStream, ImageCompressorConfig config){
		try {
			Builder<InputStream> builder = Thumbnails.fromInputStreams(Arrays.asList(imageInputStream));
			configBuilder(builder, config);
			ByteArrayOutputStream os = new ByteArrayOutputStream(BUF_SIZE);
			builder.toOutputStream(os);
			InputStream in = new ByteArrayInputStream(os.toByteArray());
			return in;
		} catch (Exception e) {
			throw new BaseException("compress image stream error: " + e.getMessage(), e);
		} finally{
			//由调用者自行处理
//			FileUtils.close(imageInputStream);
		}
	}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:16,代码来源:ImageCompressor.java

示例9: thumb

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
/**
 * 缩略图片
 * 
 * @param filePath
 *            源图片位置
 * @param thumbPath
 *            缩略后的位置
 * @param width
 *            缩略宽
 * @param height
 *            缩略高
 * @param scale
 *            按比例缩放
 * @param quality
 *            图片质量百分数
 * @param rotate
 *            旋转角度
 * @return
 */
public static String thumb(String filePath, String thumbPath, int width, int height, double scale, double quality, double rotate) {
	File img = new File(thumbPath);

	if (img.exists()) {
		return img.getPath();
	}
	Builder<File> f = Thumbnails.of(filePath);
	if (width > 0 && height > 0) {
		f.size(width, height);
	}
	if (scale > 0.0D) {
		f.scale(scale);
	}
	if (quality > 0.0D) {
		f.outputQuality(quality);
	}
	if (rotate > 0.0D) {
		f.rotate(rotate);
	}
	try {
		f.toFile(img);
		return img.getPath();
	} catch (IOException e) {
		logger.warn(e.getMessage());
	}
	return filePath;
}
 
开发者ID:Wccczy,项目名称:Student_Register,代码行数:47,代码来源:ThumbExec.java

示例10: thumb

import net.coobird.thumbnailator.Thumbnails.Builder; //导入依赖的package包/类
/**
 * 缩略图片
 * 
 * @param filePath 源图片位置
 * @param thumbPath 缩略后的位置
 * @param width 缩略宽
 * @param height 缩略高
 * @param scale 按比例缩放
 * @param quality 图片质量百分数
 * @param rotate 旋转角度
 * @return
 */
public static String thumb(String filePath, String thumbPath, int width, int height, double scale, double quality, double rotate) {
    File img = new File(thumbPath);

    if (img.exists()) {
        return img.getPath();
    }
    Builder<File> f = Thumbnails.of(filePath);
    if (width > 0 && height > 0) {
        f.size(width, height);
    }
    if (scale > 0.0D) {
        f.scale(scale);
    }
    if (quality > 0.0D) {
        f.outputQuality(quality);
    }
    if (rotate > 0.0D) {
        f.rotate(rotate);
    }
    try {
        f.toFile(img);
        return img.getPath();
    } catch (IOException e) {
        logger.warn(e.getMessage());
    }
    return filePath;
}
 
开发者ID:mattxia,项目名称:unique-web,代码行数:40,代码来源:ThumbExec.java


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