当前位置:网站首页>Processing picture class library
Processing picture class library
2022-06-25 09:38:00 【String-int】
POM.XML
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
<!-- Processing picture class library -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version>
</dependency>
JAVA
package com.example.demo;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;
import net.coobird.thumbnailator.name.Rename;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class TestImg {
public static void main(String[] args) throws IOException {
//size( Width , Height )
/* * If the horizontal ratio of the picture 200 Small , High ratio 300 Small , unchanged * If the horizontal ratio of the picture 200 Small , High ratio 300 Big , The height is reduced to 300, The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Small , Horizontal reduction to 200, The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Big , The picture is scaled down , Horizontal 200 Or as high as 300 */
// Scene application
/** *1. Specify the size to zoom */
Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
.size(200, 300)
.toFile("C:\\Users\\Administrator\\Desktop\\tu/junma.jpg");
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.1.jpeg")
// .size(2560, 2048)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/0.1.jpeg");
/** * 2. Single picture is scaled equally */
// File file = new File("D:\\\\project\\\\suining\\\\processingimgs\\\\src\\\\main\\\\resources\\\\static\\\\images/0.2.jpg");
// // 3.0 It's a double Type of number , Zoom ratio , Greater than 1 Just get bigger , Less than 1 Is to shrink
// Thumbnails.of(new FileInputStream(file)).scale(0.1).toFile(new File("C:\\\\Users\\\\Administrator\\\\Desktop\\\\tu/0.2.jpg"));
/** * 3. Not in proportion , Specify the size to zoom */
//keepAspectRatio(false) The default is true Scaled ,false Do not scale
// Thumbnails.of("D:\\\\project\\\\suining\\\\processingimgs\\\\src\\\\main\\\\resources\\\\static\\\\images/0.4.jpeg")
// .size(200, 300)
// .keepAspectRatio(false)
// .toFile("C:\\\\\\\\Users\\\\\\\\Administrator\\\\\\\\Desktop\\\\\\\\tu/0.4.jpg");
/** * 4. Generate thumbnails in batch */
//C:\Users\Administrator\Desktop\tu Is the folder to generate thumbnails , The pictures in the folder will be generated into thumbnails ,png It's the format of the picture
Thumbnails.of(new File("C:\\Users\\Administrator\\Desktop\\tu").listFiles()).scale(0.2).outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
/** * 5. Picture quality control , The picture size remains the same */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.5.jpeg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/0.5.jpeg");
// //outputQuality It is used to control the image quality
// Thumbnails.of(fromPic).scale(1f).outputQuality(0.25f).toFile(toPic);
//
/** * * failed !!!!!! * 6. Watermark the picture * fromPic It's the original picture ,waterPic Is a watermark image ,toPic Is the generated picture */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File waterPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg.png");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/haha.jpg");
// Thumbnails.of(fromPic).scale(0.8)
// .watermark(Positions.BOTTOM_RIGHT, ImageIO.read(waterPic), 0.5f)
// .outputQuality(0.8f).toFile(toPic);
//
watermark( Location , Watermark , transparency )
// Thumbnails.of("images/a380_1280x1024.jpg")
// .size(1280, 1024)
// .watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File("images/watermark.png")), 0.5f)
// .outputQuality(0.8f)
// .toFile("c:/a380_watermark_bottom_right.jpg");
//
// Thumbnails.of("images/a380_1280x1024.jpg")
// .size(1280, 1024)
// .watermark(Positions.CENTER, ImageIO.read(new File("images/watermark.png")), 0.5f)
// .outputQuality(0.8f)
// .toFile("c:/a380_watermark_center.jpg");
/** * 7. Rotate the picture */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg");
// Thumbnails.of(fromPic).scale(0.5).rotate(90).toFile(toPic);
/** * Image clipping */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg");
// Thumbnails.of(fromPic).sourceRegion(Positions.CENTER, 300, 300).scale(1.0).toFile(toPic);
//
// //sourceRegion()
//
// // Picture center 400*400 Region
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(Positions.CENTER, 400,400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_center.jpg");
//
// // Bottom right of the picture 400*400 Region
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(Positions.BOTTOM_RIGHT, 400,400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_bootom_right.jpg");
//
// // Specify coordinates
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(600, 500, 400, 400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_coord.jpg");
// Images uploaded by some apps may be of high quality , But when users browse the list , I don't want to show the original picture , Because the bandwidth requirements are high ,
// This can reduce the picture quality ( As mentioned above outputQuality), With outputstream The way of output stream response Show the browser
// narrow scale(0.5)、 quality outputQuality(0.1)
// narrow 0.5, quality 0.1, The output image size is only 6.2KB 了 , Greatly accelerated web The speed of browsing pictures
}
}
package com.example.demo;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.name.Rename;
import java.io.File;
import java.io.IOException;
public class ThumbnailatorTest {
public static void main(String[] args) throws IOException {
// File directory=new File("C:\\Users\\Administrator\\Desktop\\tu");
// Thumbnails.of(directory.listFiles())
// .size(200, 200)
// .outputFormat("jpeg")
// .asFiles(Rename.PREFIX_DOT_THUMBNAIL);
Thumbnails.of(new File("C:\\Users\\Administrator\\Desktop\\tu").listFiles())
.size(300, 200).keepAspectRatio(false).outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
}
}
package com.example.demo;
import com.sun.istack.internal.logging.Logger;
import jdk.management.resource.internal.inst.InitInstrumentation;
import net.coobird.thumbnailator.Thumbnailator;
import net.coobird.thumbnailator.Thumbnails;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
@RestController
public class TestController {
@RequestMapping("test")
public void getImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
Thumbnails.of(new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.1.jpeg"))
.size(300,200).outputFormat("jpg").toOutputStream(response.getOutputStream());
}
}
边栏推荐
- Remittance international empowers cross-border e-commerce: to be a compliant cross-border payment platform!
- [zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
- neo4jDesktop(neo4j桌面版)配置自动启动(开机自启)
- The first techo day Tencent technology open day, 628 waiting for you!
- Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
- Make a skylearn high-dimensional dataset_ Circles and make_ moons
- JMeter interface test, associated interface implementation steps (token)
- Work of the 15th week
- 【mysql学习笔记21】存储引擎
- Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
猜你喜欢

Specific usage of sklearn polynomialfeatures

将jar包注册为服务,实现开机自动启动

CSV parameterization in JMeter

Register the jar package as a service to realize automatic startup after startup

Japanese online notes for postgraduate entrance examination (9): composition template

可穿戴设备或将会泄露个人隐私

Cassava tree disease recognition based on vgg16 image classification

【mysql学习笔记22】索引

C语言刷题随记 —— 猴子吃桃

行业春寒回暖,持续承压的酒店企业于何处破局?
随机推荐
Matplotlib simple logistic regression visualization
How to download the school logo, school name and corporate logo on a transparent background without matting
The first techo day Tencent technology open day, 628 waiting for you!
How to delete a blank page that cannot be deleted in word
[design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition
Analysis on the bottom calling process of micro service calling component ribbon
使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)
Applet cloud development joint table data query and application in cloud function
Atguigu---01-scaffold
汇付国际为跨境电商赋能:做合规的跨境支付平台!
Match a mobile number from a large number of mobile numbers
Summarize two methods of configuring pytorch GPU environment
在指南针上面开户好不好,安不安全?
Voiceprint Technology (III): voiceprint recognition technology
Atguigu---18-component
x86的编码格式
瑞吉外卖项目(二)
What functions should smart agriculture applet system design have