DTCMS,添加文章时,内容中第一张图片作缩略图,并且等比例缩放图片
DTCMS,添加文章时,内容中第一张图片作缩略图
admin/article/article_edit.aspx.cs
导入:
using System.Drawing;
using System.Drawing.Imaging;
private bool DoAdd()方法
//是否将编辑器远程图片保存到本地
if (siteConfig.fileremote == )
{
model.content = AutoRemoteImageSave(txtContent.Value);
后面加入:
//设置内容中第一张图片为缩略图 Regex reg = new Regex("IMG[^>]*?src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^\']*)')", RegexOptions.IgnoreCase);
MatchCollection m = reg.Matches(model.content);
foreach (Match math in m)
{
if (math.Index >)
{ string imgUri = math.Groups[].Value;
if (imgUri != string.Empty)
{
string mini = imgUri.ToLower().Substring(imgUri.LastIndexOf("."));
string path = imgUri.Substring(0, imgUri.Length - mini.Length);
BLL.siteconfig bll_config = new BLL.siteconfig();
Model.siteconfig m_config = bll_config.loadConfig();
int h = m_config.thumbnailheight;
int w = m_config.thumbnailwidth;
Bitmap bmp = new Bitmap(Server.MapPath(imgUri));
Bitmap bmp_new = ZoomImage(bmp, h, w);
switch (mini)
{
case ".jpg": bmp_new.Save(Server.MapPath(path + "_thum" + mini), ImageFormat.Jpeg); break;
case ".gif": bmp_new.Save(Server.MapPath(path + "_thum" + mini), ImageFormat.Gif); break;
} hidFocusPhoto.Value = path + "_thum" + mini;
break;
}
} }
添加方法:
#region 等比例缩放图片
private Bitmap ZoomImage(Bitmap bitmap, int destHeight, int destWidth)
{
try
{ System.Drawing.Image sourImage = bitmap;
int width = , height = ;
//按比例缩放
int sourWidth = sourImage.Width;
int sourHeight = sourImage.Height;
if (sourHeight > destHeight || sourWidth > destWidth)
{
if ((sourWidth * destHeight) > (sourHeight * destWidth))
{
width = destWidth;
height = (destWidth * sourHeight) / sourWidth;
}
else
{
height = destHeight;
width = (sourWidth * destHeight) / sourHeight;
}
}
else
{
width = sourWidth;
height = sourHeight;
}
Bitmap destBitmap = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage(destBitmap);
g.Clear(Color.Transparent);
//设置画布的描绘质量
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourImage, new Rectangle((destWidth - width) / , (destHeight - height) / , width, height), , , sourImage.Width, sourImage.Height, GraphicsUnit.Pixel);
g.Dispose();
//设置压缩质量
System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
long[] quality = new long[];
quality[] = ;
System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
encoderParams.Param[] = encoderParam;
sourImage.Dispose();
return destBitmap;
}
catch
{
return bitmap;
}
}
#endregion
DTCMS,添加文章时,内容中第一张图片作缩略图,并且等比例缩放图片的更多相关文章
- php获取内容中第一张图片地址
$note = '<img src="http://images.xxx.com/article/cover/201601/20/141539161273.png?imageView2 ...
- dede调取文章内容的第一张图片
dede调用文章第一张图片(非缩略图)的实现方法 这篇文章主要是介绍dede调用文章第一张图片的实现代码,需要的朋友可以参考下 需要进行两个操作 第一步,修改include/extend.func.p ...
- dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法
dedecms添加文章时提示标题为空,编辑文章时编辑器空白的解决办法 dedecms出现这个问题与代码无关,主要是和PHP的版本有关,用的PHP5.4,更换成PHP5.2之后就不会有这个问题了. 问题 ...
- PHP获取网站中文章的第一张图片作为缩略图的方法
调取文章中的第一张图作为列表页缩略图是很流行的做法,WordPress中一般主题默认也是如此,那我们接下来就一起来看看PHP获取网站中各文章的第一张图片的代码示例 $temp=mt_rand(1,4) ...
- 【dedecms】DEDE列表页调用文章内容第一张图片(非缩略图)方法
打开 ../ include/ common.func.php 添加代码 //将缩放图转变为文章第一张图片 function firstimg($str_pic) { $str_sub=substr( ...
- 自动获取wordpress日志中的第一张图片作为缩略图
图片在博客中算是吸引访客阅读欲望的一种方法,在日志列表如果有一张吸引力十足的图片作为缩略图,70%的游客会点击浏览具体的文章.既然那样,赶紧去加缩略图吧. 我们知道 WordPress 有个日志缩略图 ...
- Thinkphp发布文章获取第一张图片为缩略图实现方法
正则匹配图片地址获取第一张图片地址 此为函数 在模块或是全局Common文件夹中的function.php中 /** * [getPic description] * 获取文本中首张图片地址 * @p ...
- DESTOON系统文章模块默认设置第一张图片为标题图的方法
连上FTP或者其他方法打开网站目录下的\module\article\admin\template\edit.tpl.php修改设置内容第 <input name="post[thum ...
- ECShop 添加文章时作者默认为当前登录用户
打开admin\article.php文件 查找代码 $article['is_open'] = 1; 在下边添加代码 $article['author'] = $_SESSION['admin_na ...
随机推荐
- Centos 改ssh 端口
1.修改配置文件:/etc/ssh/sshd_config 2.修改 #Port 22 把前面的#注释删掉,然后添加一个Port XXXX 定义一个自己的.例如我喜欢 Port 22333 3.修改后 ...
- Homestead can not mount nfs on macos catalina
It's not a vagrant issue but nfsd/macos issue.If you add to /etc/exports line:/Users/USERNAME/Docume ...
- 三十九.NoSQL概述 部署Redis服务 、 部署LNMP+Redis
1. 搭建Redis服务器 在主机 192.168.4.50 上安装并启用 redis 服务 设置变量test,值为123 查看变量test的值 1.1 搭建redis服务器 1.1.1 安装re ...
- php文件上传下载组件
核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...
- Educational Codeforces Round 70
目录 Contest Info Solutions A. You Are Given Two Binary Strings... B. You Are Given a Decimal String.. ...
- 爬虫(七):爬取猫眼电影top100
一:分析网站 目标站和目标数据目标地址:http://maoyan.com/board/4?offset=20目标数据:目标地址页面的电影列表,包括电影名,电影图片,主演,上映日期以及评分. 二:上代 ...
- 数据结构实验之图论十一:AOE网上的关键路径【Bellman_Ford算法】
Problem Description 一个无环的有向图称为无环图(Directed Acyclic Graph),简称DAG图. AOE(Activity On Edge)网:顾名思义,用边 ...
- python对象调用父类的方法
#类定义 class People: #定义基本属性 name = '' age = 0 #定义私有属性,私有属性在类外部无法直接进行访问 __weight = 0 #定义构造方法 def __ini ...
- CF786E ALT
题意 有一棵 \(n\) 个点的树和 \(m\) 个人,第 \(i\) 个人从 \(u_i\) 走到 \(v_i\) 现在要发宠物,要求一个人要么他自己发到宠物,要么他走的路径上的都有宠物. 求最小代 ...
- cesium地下模式(地表透明)3
这篇博客主要解决“瓦片的白色网格”问题 设置skirt=0可以解决这个问题,需要设置3个地方 1.HeightmapTerrainData.js createMesh方法 this._skirtHei ...