本文整理了Java中net.coobird.thumbnailator.Thumbnails
类的一些代码示例,展示了Thumbnails
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thumbnails
类的具体详情如下:
包路径:net.coobird.thumbnailator.Thumbnails
类名称:Thumbnails
[英]Provides a fluent interface to create thumbnails.
This is the main entry point for creating thumbnails with Thumbnailator.
By using the Thumbnailator's fluent interface, it is possible to write thumbnail generation code which resembles written English. Usage: The following example code demonstrates how to use the fluent interface to create a thumbnail from multiple files from a directory, resizing them to a maximum of 200 pixels by 200 pixels while preserving the aspect ratio of the original, then saving the resulting thumbnails as JPEG images with file names having thumbnail. appended to the beginning of the file name.
Thumbnails.of(directory.listFiles())
.size(200, 200)
.outputFormat("jpeg")
.asFiles(Rename.PREFIX_DOT_THUMBNAIL);
// English: "Make thumbnails of files in the directory, with a size of 200x200,
with output format of JPEG, and save them as files while renaming
the files to be prefixed with a 'thumbnail.'."
For more examples, please visit the Thumbnailator project page.
Important Implementation Notes Upon calling one of the Thumbnails.of(...) methods, in the current implementation, an instance of an inner class of this class is returned. In most cases, the returned instance should not be used by storing it in a local variable, as changes in the internal implementation could break code in the future.
As a rule of thumb, always method chain from the Thumbnails.ofall the way until the output method (e.g. toFile, asBufferedImage, etc.) is called without breaking them down into single statements. See the "Usage" section above for the intended use of the Thumbnailator's fluent interface. Unintended Use:
// Unintended use - not recommended!
Builder<File> instance = Thumbnails.of("path/to/image");
instance.size(200, 200);
instance.asFiles("path/to/thumbnail");
[中]
代码示例来源:origin: coobird/thumbnailator
Thumbnails.of(inFile)
.size(width, height)
.toFile(outFile);
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails for images with the specified filenames.
*
* @param files File names of image files for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty collection.
* @since 0.3.1
*/
public static Builder<File> fromFilenames(Iterable<String> files)
{
checkForNull(files, "Cannot specify null for input files.");
checkForEmpty(files, "Cannot specify an empty collection for input files.");
return Builder.ofStrings(files);
}
代码示例来源:origin: coobird/thumbnailator
/**
* Creates a thumbnail from an image file, and returns as a
* {@link BufferedImage}.
*
* @param f The {@link File} from which image data is read.
* @param width The width of the thumbnail.
* @param height The height of the thumbnail.
* @return The thumbnail image as a {@link BufferedImage}.
* @throws IOException Thrown when a problem occurs when reading from
* {@code File} representing an image file.
*/
public static BufferedImage createThumbnail(
File f,
int width,
int height
) throws IOException
{
validateDimensions(width, height);
if (f == null)
{
throw new NullPointerException("Input file is null.");
}
return Thumbnails.of(f).size(width, height).asBufferedImage();
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link BufferedImage}s.
*
* @param images {@link BufferedImage}s for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty collection.
* @since 0.3.1
*/
public static Builder<BufferedImage> fromImages(Iterable<BufferedImage> images)
{
checkForNull(images, "Cannot specify null for images.");
checkForEmpty(images, "Cannot specify an empty collection for images.");
return Builder.ofBufferedImages(images);
}
代码示例来源:origin: coobird/thumbnailator
Thumbnails.of(is)
.size(width, height)
.outputFormat(format)
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link File}s.
*
* @param files {@link File} objects of image files for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty collection.
* @since 0.3.1
*/
public static Builder<File> fromFiles(Iterable<File> files)
{
checkForNull(files, "Cannot specify null for input files.");
checkForEmpty(files, "Cannot specify an empty collection for input files.");
return Builder.ofFiles(files);
}
代码示例来源:origin: sanluan/PublicCMS
public void thumb(String sourceFilePath, String thumbFilePath, Integer width, Integer height) throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(thumbFilePath);) {
Thumbnails.of(sourceFilePath).size(width, height).toOutputStream(outputStream);
}
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails for images with the specified {@link URL}s.
*
* @param urls URLs of the images for which thumbnails
* are to be produced.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty collection.
* @since 0.3.1
*/
public static Builder<URL> fromURLs(Iterable<URL> urls)
{
checkForNull(urls, "Cannot specify null for input URLs.");
checkForEmpty(urls, "Cannot specify an empty collection for input URLs.");
return Builder.ofUrls(urls);
}
代码示例来源:origin: sanluan/PublicCMS
public void thumb(String sourceFilePath, String thumbFilePath, Integer width, Integer height) throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(thumbFilePath);) {
Thumbnails.of(sourceFilePath).size(width, height).toOutputStream(outputStream);
}
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails for images obtained from the specified
* {@link InputStream}s.
*
* @param inputStreams {@link InputStream}s which provide images for
* which thumbnails are to be produced.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty collection.
* @since 0.3.1
*/
public static Builder<InputStream> fromInputStreams(Iterable<? extends InputStream> inputStreams)
{
checkForNull(inputStreams, "Cannot specify null for InputStreams.");
checkForEmpty(inputStreams, "Cannot specify an empty collection for InputStreams.");
return Builder.ofInputStreams(inputStreams);
}
代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin
private static BufferedImage resizeNormalImage(BufferedImage image,
ImageInformation information) throws IOException {
int newWidth = image.getWidth();
int newHeight = image.getHeight();
if (MathUtils.floatEquals(information.getFactor(), 1f)) {
return image;
}
if (information.getFactor() >= 0) {
newWidth = (int) (newWidth * information.getFactor());
newHeight = (int) (newHeight * information.getFactor());
}
BufferedImage resizedImage = null;
switch (information.getAlgorithm()) {
case SCALR:
Scalr.Method scalrMethod = (Scalr.Method) information.getMethod();
resizedImage = Scalr.resize(image, scalrMethod, newWidth, newHeight, Scalr.OP_ANTIALIAS);
break;
case THUMBNAILATOR:
return Thumbnails.of(image)
.size(newWidth, newHeight)
.asBufferedImage();
}
return resizedImage;
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails for images with the specified filenames.
*
* @param files File names of image files for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty array.
*/
public static Builder<File> of(String... files)
{
checkForNull(files, "Cannot specify null for input files.");
checkForEmpty(files, "Cannot specify an empty array for input files.");
return Builder.ofStrings(Arrays.asList(files));
}
代码示例来源:origin: jmrozanec/pdf-converter
private void persistImage(BufferedImage image, int width, int height, File output) throws IOException {
System.out.println(output);
output.getParentFile().mkdirs();
ImageIO.write(Thumbnails.of(image).size(width, height).asBufferedImage(), FilenameUtils.getExtension(output.getAbsolutePath()), output);
}
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link URL}s.
*
* @param urls {@link URL} objects of image files for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty array.
*/
public static Builder<URL> of(URL... urls)
{
checkForNull(urls, "Cannot specify null for input URLs.");
checkForEmpty(urls, "Cannot specify an empty array for input URLs.");
return Builder.ofUrls(Arrays.asList(urls));
}
代码示例来源:origin: sosoapi/framework
/**
*
*@name 根据指定长度和宽度生成缩略图,维持原宽高比例
*@Description 相关说明
*@Time 创建时间:2014-7-22上午9:30:11
*/
public static byte[] thumbBySizeWithScale(byte[] content,int width,int length){
InputStream inputStream = new ByteArrayInputStream(content);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Thumbnails
.of(inputStream)
.size(width,length)
.toOutputStream(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
return outputStream.toByteArray();
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link File}s.
*
* @param files {@link File} objects of image files for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty array.
*/
public static Builder<File> of(File... files)
{
checkForNull(files, "Cannot specify null for input files.");
checkForEmpty(files, "Cannot specify an empty array for input files.");
return Builder.ofFiles(Arrays.asList(files));
}
代码示例来源:origin: sosoapi/framework
/**
*
*@name 按照比例进行缩放
*@Description 相关说明
*@Time 创建时间:2014-7-22上午9:30:11
*/
public static byte[] thumbByScale(byte[] content,double scale){
InputStream inputStream = new ByteArrayInputStream(content);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Thumbnails
.of(inputStream)
.scale(scale)
.toOutputStream(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
return outputStream.toByteArray();
}
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link InputStream}s.
*
* @param inputStreams {@link InputStream}s which provide the images
* for which thumbnails are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty array.
*/
public static Builder<? extends InputStream> of(InputStream... inputStreams)
{
checkForNull(inputStreams, "Cannot specify null for InputStreams.");
checkForEmpty(inputStreams, "Cannot specify an empty array for InputStreams.");
return Builder.ofInputStreams(Arrays.asList(inputStreams));
}
代码示例来源:origin: sosoapi/framework
/**
*
*@name 根据指定长度和宽度生成缩略图,维持原宽高比例
*@Description 相关说明
*@Time 创建时间:2014-7-22上午9:30:11
*/
public static byte[] thumbBySizeWithScale(String filePath,int width,int length){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Thumbnails
.of(filePath)
.size(width,length)
.toOutputStream(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
return outputStream.toByteArray();
}
代码示例来源:origin: coobird/thumbnailator
/**
* Indicate to make thumbnails from the specified {@link BufferedImage}s.
*
* @param images {@link BufferedImage}s for which thumbnails
* are to be produced for.
* @return Reference to a builder object which is used to
* specify the parameters for creating the thumbnail.
* @throws NullPointerException If the argument is {@code null}.
* @throws IllegalArgumentException If the argument is an empty array.
*/
public static Builder<BufferedImage> of(BufferedImage... images)
{
checkForNull(images, "Cannot specify null for images.");
checkForEmpty(images, "Cannot specify an empty array for images.");
return Builder.ofBufferedImages(Arrays.asList(images));
}
内容来源于网络,如有侵权,请联系作者删除!