图片缩略处理


import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zj
 * @since 1.0
 **/
@Slf4j
public class ThumbnailsUtils {


    public static void thumbnails(String sourceFilePath, String thumbnailsPath) {
        try {
            Thumbnails.of(sourceFilePath)
                    .scale(0.3f)
                    .outputQuality(0.3f)
                    .toFile(thumbnailsPath);
        } catch (IOException e) {
            log.error("生成缩略图失败", e);
        }
    }

    public static void thumbnails(InputStream sourceFileInputStream, String thumbnailsPath) {
        try {
            Thumbnails.of(sourceFileInputStream)
                    .scale(0.3f)
                    .outputQuality(0.3f)
                    .toFile(thumbnailsPath);
        } catch (IOException e) {
            log.error("生成缩略图失败", e);
        }
    }
}

 

没有账号? 忘记密码?

社交账号快速登录