我正在尝试获取 ImageGen 为图片库下载部分生成的缩略图 jpg 的文件大小。
我以前在 Umbraco 4.2 中做过,但我正在尝试更新我的 XSLT 并为 Umbraco 4.9 简化它
4.2版方法:
<xsl:value-of select="emint:GetFileSize(((memberGroupFunctions:GetFileSize(concat(substring-before($mediaNode/data [@alias='umbracoFile'],'.'), '_thumb_1200.jpg')) div 1024) div 1024))" />
我要为 4.9 版做什么:
<xsl:value-of select="emint:GetFileSize(((memberGroupFunctions:GetFileSize(concat(substring-before(umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoFile,'.'), '_thumb_1200.jpg')) div 1024) div 1024))" />
我不明白为什么它不起作用。原始图像被上传到媒体部分,它被切割成各种尺寸,包括 1200 和 2400。然后使用媒体选择器数据类型在内容部分中选择原始图像。然后我将它和页面上的“拇指”版本显示为可下载的链接。该链接包括图像的宽度、高度和文件大小。我只是无法在“拇指”图像上获得文件大小!宽度和高度显示。但是“拇指”图像的 GetFileSize 会导致“解析 XSLT 文件时出错”错误。
<ul>
<li>
<a href="{concat(substring-before(umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoFile,'.'), '_thumb_1200.jpg')}" title="Medium">
Medium - <xsl:value-of select="emint:GetThumbailFileDimensionWidth(1200, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoHeight div 1, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoWidth div 1)"/> x <xsl:value-of select="emint:GetThumbailFileDimensionHeight(1200, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoHeight div 1, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoWidth div 1)"/> px
<xsl:value-of select="emint:GetFileSize(((memberGroupFunctions:GetFileSize(concat(substring-before(umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoFile,'.'), '_thumb_1200.jpg')) div 1024) div 1024))" />
</a>
</li>
<li>
<a href="{concat(substring-before(umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoFile,'.'), '_thumb_2400.jpg')}" title="Large">
Large - <xsl:value-of select="emint:GetThumbailFileDimensionWidth(2400, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoHeight div 1, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoWidth div 1)"/> x <xsl:value-of select="emint:GetThumbailFileDimensionHeight(2400, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoHeight div 1, umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoWidth div 1)"/> px
<xsl:value-of select="emint:GetFileSize((umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoBytes div 1024) div 1024)" />
</a>
</li>
<li>
<a href="{umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoFile}" title="Original File">
Original File - <xsl:value-of select="umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoWidth" /> x <xsl:value-of select="umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoHeight" /> px
- <xsl:value-of select="emint:GetFileSize((umbraco.library:GetMedia($currentPage/imageGalleryPhoto, 'false')/umbracoBytes div 1024) div 1024)" />
</a>
</li>
</ul>
下载列表应如何显示的示例:
- 中 - 1200 x 898 像素 - 225 KB
- 大 - 2400 x 1797 像素 - 777 KB
- 原始文件 - 6658 x 4984 像素 - 10.20 MB
这是我用于宽度、高度和文件大小转换的 C# 脚本:
<msxsl:script language="C#" implements-prefix="emint">
<![CDATA[public string GetExtension(string fileName)
{
string[] terms = fileName.Split('.');
if (terms.Length <= 0)
{
return string.Empty;
}
return terms[terms.Length -1];
}
public string GetFileName(string fileName)
{
string[] terms = fileName.Split('/');
if (terms.Length <= 0)
{
return string.Empty;
}
return terms[terms.Length -1];
}
public string GetFileSize(Decimal mbs)
{
Decimal result = Decimal.Round(mbs, 2);
if (result == 0)
{
result = mbs * 1024;
return Decimal.Round(result, 2).ToString() + " KB";
}
return result.ToString() + " MB";
}
public Decimal GetThumbailSizeRatio(Decimal thumbnailSize, Decimal height, Decimal width)
{
Decimal ratio;
if (height >= width)
{
ratio = height / thumbnailSize;
}
else
{
ratio = width / thumbnailSize;
}
return ratio;
}
public string GetThumbailFileDimensionHeight(Decimal thumbnailSize, Decimal height, Decimal width)
{
Decimal ratio = GetThumbailSizeRatio(thumbnailSize, height, width);
return Decimal.Round((height / ratio), 0).ToString();
}
public string GetThumbailFileDimensionWidth(Decimal thumbnailSize, Decimal height, Decimal width)
{
Decimal ratio = GetThumbailSizeRatio(thumbnailSize, height, width);
return Decimal.Round((width/ ratio), 0).ToString();
}
public string GetCentimeters(Decimal pix)
{
Decimal formula = (decimal)0.026458333;
Decimal result = pix * formula;
return Decimal.Round(result,0).ToString();
}]]>
任何人都可以帮忙吗?
干杯,合资企业