当前位置:网站首页>老树开花——用ImageProcessor快速搭一个图床应用
老树开花——用ImageProcessor快速搭一个图床应用
2022-07-13 19:24:00 【InfoQ】
ImageProcessor简介
创建项目

引入扩展
install-package imageprocessor.web<!--configSections节点内新增-->
<sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageSecuritySection, ImageProcessor.Web"/>
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageProcessingSection, ImageProcessor.Web"/>
<section name="caching" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageCacheSection, ImageProcessor.Web"/>
</sectionGroup>
<!--system.web节点内新增-->
<httpModules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>
</httpModules>
<!--system.webServer节点内新增-->
<modules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>
</modules>
<!--根节点configuration内新增-->
<imageProcessor>
<security configSource="config\imageprocessor\security.config"/>
<caching configSource="config\imageprocessor\cache.config"/>
<processing configSource="config\imageprocessor\processing.config"/>
</imageProcessor>
看效果


- 裁剪

其余功能
using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
{
imageFactory.Load(inStream);
ISupportedImageFormat format = new JpegFormat { Quality = 70 };
Size size = new Size(150, 0);
foreach (var item in model.content_list)
{
FontFamily ff = new FontFamily(item.font_family);
TextLayer textLayer = new TextLayer()
{
Text = item.content,
FontColor = Color.FromArgb(item.color_r, item.color_g, item.color_b),
Position = new Point(item.location_x, item.location_y),
FontSize = item.font_size,
FontFamily = ff
};
imageFactory.Watermark(textLayer);
//是否生成二维码
if (item.is_qrcode == 1)
{
//生成二维码
string qrcode_path = QrCodeHelper.MakeQrcodeSaveLocal(item.qrcode_content);
#region 将图片转为流然后添加到证书模板中
FileStream fileStream = new FileStream(qrcode_path, FileMode.Open, FileAccess.Read);
int byteLength = (int)fileStream.Length;
byte[] fileBytes = new byte[byteLength];
fileStream.Read(fileBytes, 0, byteLength);
//文件流关闭,文件解除锁定
fileStream.Close();
#endregion
//将二维码水印添加到证书模板
ImageLayer imageLayer = new ImageLayer()
{
Image = Image.FromStream(new MemoryStream(fileBytes)),//先将图片转为流,然后添加到证书模板中就不会占用图片了
Position = new Point(item.qrcode.location_x, item.qrcode.location_y),
Size = new Size(item.qrcode.width, item.qrcode.height),
Opacity = item.qrcode.opacity
};
imageFactory.Overlay(imageLayer);
//是否删除本地二维码
if (item.isdel_qrcode == 1)
{
FileHelper.DeleteLocalFile(qrcode_path);
}
}
}
imageFactory.Save(outStream);
imageFactory.Dispose();
}
边栏推荐
- Message mechanism of dtcloud (3)
- 创原会丨携手50+云原生企业,共探跨越数字化鸿沟新模式
- 常用邮箱访问协议
- Detailed explanation and Simulation of string library function and memory operation library function
- odoo的assets详述
- JMeter 21 day clock in day01
- The computer regularly clears wechat data
- YOLOv5使用时遇到的问题
- Hcip day 6 notes
- Vscode input! No prompt, unable to automatically complete the solution (latest)
猜你喜欢

05.01 字符串

Vscode input! No prompt, unable to automatically complete the solution (latest)

Virtualization path of GPU resource pool

孤儿进程、僵尸进程和进程退出(针对面试)

Memory mapping principle and detailed explanation (very practical)

HCIP第二天笔记

Is there a completely independent localization database technology
![[go] II. Introduction to restful API, API process and code structure](/img/fd/8ae3d6a4c0d0c973ce81672c1c529c.png)
[go] II. Introduction to restful API, API process and code structure

【虹科技术】网络万用表在数据中心的应用

建立自己的网站(21)
随机推荐
dtcloud Qweb实战之看板视图
Anonymous pipeline principle and detailed explanation (very practical)
dtcloud的消息机制(三)
ADB环境配置
Various methods of obtaining form handle in VC
LeetCode 2155. 分组得分最高的所有下标
Message mechanism of dtcloud (3)
【canvas】canvas和svg基本使用
Is there a completely independent localization database technology
人工智能与 RPA 技术应用(一)-RPA弘玑产品介绍、设计器界面功能讲解
Interprocess communication (very practical)
LeetCode 1584. Minimum cost of connecting all points
Map set summary
php获取目录下的全部子文件名称(含案例、截图、代码)
Memory mapping principle and detailed explanation (very practical)
解释初始化列表
this指针介绍
JSP learning notes
modular
电脑定时清理微信数据