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


Java Thumbnails类代码示例

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


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

示例1: processProfileImage

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
public void processProfileImage(String providerImageUrl, String userKey)
        throws IOException {

    // Reduce original image size. Thumbnailator will not modify
    // image if less than 600x600

    BufferedImage bufferedProfileImage =
            Thumbnails.of(new URL(providerImageUrl))
                    .forceSize(600, 600)
                    .allowOverwrite(true)
                    .outputFormat("png")
                    .asBufferedImage();

    saveProfileImage(bufferedProfileImage, userKey, false);

    // Create profile image icon. Saved to separate directory

    BufferedImage bufferedIconImage =
            Thumbnails.of(new URL(providerImageUrl))
                    .forceSize(32, 32)
                    .allowOverwrite(true)
                    .outputFormat("png")
                    .asBufferedImage();

    saveProfileImage(bufferedIconImage, userKey, true);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:27,代码来源:WebUI.java

示例2: processRequest

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    
    String templateName = request.getParameter("demo_name");
    Part filePart = request.getPart("demo_img");
    try{
        // String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix.
        InputStream fileContent = filePart.getInputStream();
        System.out.println(templateName);
        File file = new File("uploads/"+templateName+".png");
        System.out.println(file.getAbsolutePath());
        OutputStream outputStream = new FileOutputStream(file);
        IOUtils.copy(fileContent, outputStream);
        outputStream.close();
        
        Thumbnails.of(new File("uploads/"+templateName+".png"))
        .size(500, 707)
        .outputFormat("PNG")
        .toFiles(Rename.NO_CHANGE);
        
    }catch(NullPointerException ex){
        System.out.println("null param");
    }
    
    response.getWriter().write("uploaded lmao");  
    
    System.out.println("fking shit");
    response.sendRedirect("init.jsp?req="+templateName);
}
 
开发者ID:lupino22,项目名称:kronometer,代码行数:41,代码来源:UploadFile.java

示例3: scaleImg

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
  * 生成缩略图
  * @param file
  * @param suffix
  * @param width
  * @param height
  * @throws IOException
  */
 public static void scaleImg(File file,String suffix,int width,int height) throws IOException{
 	if(file.isDirectory()){
 		File[] subFiles = file.listFiles();
 		for (File subFile : subFiles) {
 			scaleImg(subFile, suffix, width, height);
}
 	}else{
 		double length = file.length();
     	String path = file.getAbsolutePath();
     	int cut = path.lastIndexOf(".");
 		String prefixFile = StringUtils.substring(path, 0, cut);
 		String formatFile = StringUtils.substring(path, cut,path.length());
 		String scaleFileName = prefixFile+suffix+formatFile;
 		double quality = 1;
 		if(length>=100*1000){
 			quality = 0.8;			
 		}
 		Thumbnails.of(file).allowOverwrite(true).size(width,height).outputQuality(quality).toFile(scaleFileName);
 	}
 }
 
开发者ID:nyh137,项目名称:SSMFrameBase,代码行数:29,代码来源:ImgUtil.java

示例4: generateThumImage

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * 缩放并裁剪图片,输出缩放后的图片和缩放后裁剪的图片。
 * @param inPath   输入图片地址
 * @param outPath  缩放输出地址
 * @param outPath2 裁剪输出地址
 */
public PageData generateThumImage(String inPath, String outPath, String outPath2) {
    try {
        BufferedImage read = ImageIO.read(new File(inPath));
        int height = read.getHeight();
        int width = read.getWidth();
        if (height > width) {
            Thumbnails.of(inPath).width(this.changeWeight)
                    .toFile(outPath);
        }
        if (height < width) {
            Thumbnails.of(inPath).height(this.changeHeight)
                    .toFile(outPath);
        }
        if (height == width) {
            Thumbnails.of(inPath).forceSize(this.changeHeight, this.changeWeight)
                    .toFile(outPath);
        }
        CutImg(outPath, outPath2, height);
    } catch (IOException e) {
        e.printStackTrace();
        return WebResult.requestFailed(400, "图片压缩失败", null);
    }
    return WebResult.requestSuccess();
}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:31,代码来源:ImgChange.java

示例5: CutImg

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * 如果设置长图的长度不为0而且传入的图片高度大于设置长图的长度。就认为是长图,裁剪中心顶部,添加长图的水印。
 * @param outPath  输入路径
 * @param outPath2 输出路径
 * @param height   传入图片的高度
 */
private void CutImg(String outPath, String outPath2, int height) {
    try {
        if (this.longImageHeigh != 0 && height >= this.longImageHeigh) {
            Thumbnails.of(outPath).sourceRegion(Positions.TOP_CENTER, this.changeHeight, this.changeWeight)
                    .size(this.changeHeight, this.changeWeight)
                    .outputQuality(1d).watermark(Positions.BOTTOM_RIGHT, ImageIO.read(this.waterImageFile), 1f)
                    .toFile(outPath2);
        } else {
            Thumbnails.of(outPath).sourceRegion(Positions.CENTER, this.changeHeight, this.changeWeight)
                    .size(this.changeHeight, this.changeWeight)
                    .outputQuality(1d)
                    .toFile(outPath2);
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:25,代码来源:ImgChange.java

示例6: small

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
protected byte[] small(long uid, String uri, String size, byte[] data) throws IOException {
	String[] list = size.split("x");
	int width = Integer.parseInt(list[0]);
	int height = Integer.parseInt(list[1]);
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	ByteArrayInputStream input = new ByteArrayInputStream(data);
	Thumbnails.of(input).size(width, height).toOutputStream(output);

	// http://rensanning.iteye.com/blog/1545708 Java生成缩略图之Thumbnailator

	// Thumbnails.of(input).asBufferedImage();
	// ImageIO.getImageReader(writer)
	String uri2 = uri.replaceFirst(".jpg", "_" + size + ".jpg");
	byte[] data2 = output.toByteArray();
	if (data2.length <= 0) {
		throw new FileNotFoundException("怎么压缩后的图片会为空[" + uri2 + "]?");
	}
	dfsService.write(uri2, data2, uid);
	return data2;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:21,代码来源:ThumbnailServiceSizeImpl.java

示例7: crop

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
protected byte[] crop(long uid, String uri, String size, byte[] data) throws IOException {
	if (data.length <= 0) {
		throw new IllegalArgumentException("图片文件不能为空.");
	}
	String[] list = size.split("x");
	int width = Integer.parseInt(list[0]);
	int height = Integer.parseInt(list[1]);
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	ByteArrayInputStream input = new ByteArrayInputStream(data);
	// Thumbnails.of(input).size(width, height).toOutputStream(output);

	Thumbnails.of(input).crop(Positions.CENTER).size(width, height).keepAspectRatio(true).toOutputStream(output);

	// http://rensanning.iteye.com/blog/1545708 Java生成缩略图之Thumbnailator

	// Thumbnails.of(input).asBufferedImage();
	// ImageIO.getImageReader(writer)
	String uri2 = uri.replaceFirst(".jpg", "_" + size + "_crop.jpg");
	byte[] data2 = output.toByteArray();
	dfsService.write(uri2, data2, uid);
	return data2;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:23,代码来源:ThumbnailServiceCropImpl.java

示例8: crop

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * 图像切割(按指定起点坐标和宽高切割)
 */
@SneakyThrows
public static ByteArrayOutputStream crop(@Nonnull InputStream inputStream, int x, int y, int width, int height) {
    checkNotNull(inputStream);
    checkArgument(x >= 0);
    checkArgument(y >= 0);
    checkArgument(width > 0);
    checkArgument(height > 0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Thumbnails.of(inputStream)
            .sourceRegion(Positions.TOP_LEFT, width, height)
            .size(width, height)
            .outputFormat(IMAGE_TYPE_JPG)
            .toOutputStream(baos);
    return baos;
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:19,代码来源:TcImageUtils.java

示例9: calculateMaxSizeInFixedAspectRatio

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * 计算最大宽高
 */
@SneakyThrows
public static TcPair<Integer, Integer> calculateMaxSizeInFixedAspectRatio(@Nonnull InputStream inputStream,
                                                                          double ratio) {
    checkNotNull(inputStream);
    checkArgument(ratio > 0);
    BufferedImage img = Thumbnails.of(inputStream).scale(1).asBufferedImage();
    int width = img.getWidth();
    int height = img.getHeight();
    double imgRatio = (double) width / (double) height;
    if (imgRatio > ratio) {
        width = (int) ((double) width * ratio / imgRatio);
    } else {
        height = (int) ((double) height * imgRatio / ratio);
    }
    return TcPair.with(width, height);
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:20,代码来源:TcImageUtils.java

示例10: visualizeMulti

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
@Override
protected String visualizeMulti(List<Map<String, PrimitiveTypeProvider>> featureData){
  BufferedImage image = new BufferedImage(featureData.size(), 1, BufferedImage.TYPE_INT_RGB);
  int count = 0;
  for (Map<String, PrimitiveTypeProvider> feature : featureData) {
    int[][] avg = ArtUtil.shotToInt(feature.get("feature").getFloatArray(), 1, 1);
    image.setRGB(count, 0, avg[0][0]);
    count++;
  }

  try {
    image = Thumbnails.of(image).scalingMode(ScalingMode.BILINEAR).scale(10, 1).asBufferedImage();
  } catch (IOException e) {
    e.printStackTrace();
  }

  return ImageParser.BufferedImageToDataURL(image, "png");
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:19,代码来源:VisualizationAverageColorGradient.java

示例11: classifyImage

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * Classifies an Image with the given neural net.
 * Performs 3 Classifications with different croppings, maxpools the vectors on each dimension to get hits
 */
private float[] classifyImage(BufferedImage img) {
    float[] probs = new float[1000];
    Arrays.fill(probs, 0f);
    Position[] positions = new Position[3];
    positions[0] = Positions.CENTER;
    if (img.getHeight() > img.getWidth()) {
        positions[1] = Positions.TOP_RIGHT;
        positions[2] = Positions.BOTTOM_RIGHT;
    } else {
        positions[1] = Positions.CENTER_RIGHT;
        positions[2] = Positions.CENTER_LEFT;
    }

    float[] curr;
    for (Position pos : positions) {
        try {
            curr = getNet().classify(Thumbnails.of(img).size(224, 224).crop(pos).asBufferedImage());
            probs = NeuralNetUtil.maxpool(curr, probs);
        } catch (IOException e) {
            LOGGER.error(e);
        }
    }
    return probs;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:29,代码来源:NeuralNetVGG16Feature.java

示例12: thumbBySizeWithoutScale

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
/**
 * 
		*@name 根据指定长度和宽度生成缩略图,不维持原宽高比例
		*@Description 相关说明 
		*@Time 创建时间:2014-7-22上午9:30:11
 */
public static byte[] thumbBySizeWithoutScale(byte[] content,int width,int length){
	InputStream inputStream = new ByteArrayInputStream(content);
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	try {
		Thumbnails
				.of(inputStream)
				.size(width,length)
				.keepAspectRatio(false)
				.toOutputStream(outputStream);
	} catch (IOException e) {
		e.printStackTrace();
	}

	return outputStream.toByteArray();
}
 
开发者ID:yinshipeng,项目名称:sosoapi-base,代码行数:22,代码来源:ImgUtils.java

示例13: compressTo

import net.coobird.thumbnailator.Thumbnails; //导入依赖的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

示例14: main

import net.coobird.thumbnailator.Thumbnails; //导入依赖的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

示例15: resize

import net.coobird.thumbnailator.Thumbnails; //导入依赖的package包/类
public void resize(File folder, File outFolder) {
	if (!outFolder.exists()) {
		outFolder.mkdirs();
	}

	for (File file : folder.listFiles()) {
		List<File> files = new ArrayList<File>();
		files.add(file);
		try {
			Thumbnails
					.fromFiles(files)
					.size(400, 400)
					.toFile(outFolder.getPath() + File.separator
							+ file.getName());
		} catch (Exception e) {
			System.err.println(file.getName());
		}
	}
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:20,代码来源:ResizeImg.java


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