圖片縮略處理


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);
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章