| | |
| | | package com.ruoyi.file.utils; |
| | | |
| | | import cn.hutool.core.img.ImgUtil; |
| | | import cn.hutool.extra.qrcode.QrCodeUtil; |
| | | import com.aliyun.oss.ClientException; |
| | | import com.aliyun.oss.OSS; |
| | |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.awt.*; |
| | | import java.io.*; |
| | | import java.util.Calendar; |
| | | |
| | |
| | | public class OBSUploadUtils { |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | String activityId = "123"; |
| | | String backImageUrl = "2023/8/3/6742e22f748349429e454c9c6ba168ee.jpg"; |
| | | String fileUrl = null; |
| | | File qrCodeFile = new File("/home/image/qrcode.png"); |
| | | // 二维码内容 |
| | | String text = "https://wxapp.hhhrt.cn/mini/activity?"+activityId; |
| | | String text = "https://wxapp.hhhrt.cn/mini/coupon"; |
| | | // 生成二维码 |
| | | QrCodeUtil.generate(text, 100, 100, qrCodeFile); |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | InputStream codeStream = new FileInputStream(qrCodeFile); |
| | | InputStream backStream = OBSUploadUtils.getOSSInputStream(backImageUrl); |
| | | // 将图片合成在一起 |
| | | ImgUtil.pressImage( |
| | | backStream, // 主图片 |
| | | out, // 输出图片 |
| | | ImgUtil.read(codeStream).getScaledInstance(200, 200, Image.SCALE_DEFAULT), //水印图片 |
| | | 0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移 |
| | | 350, //y坐标修正值。 默认在中间,偏移量相对于中间偏移 |
| | | 1.0f |
| | | ); |
| | | InputStream inputStream = new ByteArrayInputStream(out.toByteArray()); |
| | | fileUrl = OBSUploadUtils.uploadInputStream(inputStream,activityId); |
| | | fileUrl = OBSUploadUtils.uploadInputStream(codeStream,"couponCode"); |
| | | System.out.println(fileUrl); |
| | | } |
| | | |