package com.ruoyi.file.config;


import cn.hutool.core.img.ImgUtil;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.awt.image.BufferedImage;
import java.io.File;


@Configuration
@ConfigurationProperties(prefix = "ruoyi.file")
@Data
@Slf4j
public class SpringFileStorageProperties extends org.dromara.x.file.storage.spring.SpringFileStorageProperties {

  private Integer maxWidth;
  private Integer maxHeight;
  private File watermark;
  private Integer thWidth;
  private Integer thHeight;
  @Getter
  @Setter(AccessLevel.PRIVATE)
  private BufferedImage watermarkImage;

  @PostConstruct
  public void init() {
    try {
      if (watermark != null && watermark.isFile()) {
        watermarkImage = ImgUtil.read(watermark);
        log.warn("水印图片加载成功:" + watermark.toString());
      }
    } catch (Exception e) {
      log.warn("初始化水印失败", e);
    }
  }
}
