获取Umbraco缩略图图像文件大小 - umbracoBytes XSLT

时间:2012-10-23 04:33:46

标签: xslt umbraco thumbnails

我正在尝试获取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.然后使用Media Picker数据类型在“内容”部分中选择原始图像。然后我在页面上显示它和“拇指”版本作为可下载的链接。链接包括图像宽度,高度和文件大小。我只是无法获得“拇指”图像上的文件大小!宽度和高度显示。但是“拇指”图像的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 px - 225 KB
  • 大 - 2400 x 1797 px - 777 KB
  • 原始文件 - 6658 x 4984 px - 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();
  }]]>

有人可以帮忙吗?

干杯,JV

1 个答案:

答案 0 :(得分:0)

您可以使用ImageGen生成图片吗?

如果是,您必须安装 ImageGenerator 这是生成任意大小图片的非常有用的工具,您需要从 <安装在 Umbraco CMS 中的em>开发人员 部分。

此外,还有文档如何使用ImageGen Documentation

我希望这会有所帮助