Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    Oct 23, 2012 @ 06:39
    syn-rg
    0

    Get Umbraco thumbnail image file size - umbracoBytes XSLT

    I'm trying get the file size of the thumbnail jpg generated by ImageGen for an image gallery download section.

    I've done it before in Umbraco 4.2 but I'm trying to update my XSLT and simplify it for Umbraco 4.9

    Version 4.2 method:

    <xsl:value-of select="emint:GetFileSize(((memberGroupFunctions:GetFileSize(concat(substring-before($mediaNode/data [@alias='umbracoFile'],'.'), '_thumb_1200.jpg')) div 1024) div 1024))" />

    What I'm trying to do for Version 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))" />

    I can't understand why it's not working. The original image is uploaded to the Media seciton, it's cut to various sizes, including 1200 and 2400. The original image is then selected in the Content section using the Media Picker datatype. I then display it and the "thumb" versions on the page as downloadable links. The link includes the images width, height and file size. I just can't get the file size working on the "thumb" images! The width and height display. But the GetFileSize for the "thumb" images causes an "Error parsing XSLT file" error.

    <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>

    Example of how the download list should display:

    • Medium - 1200 x 898 px - 225 KB
    • Large - 2400 x 1797 px - 777 KB
    • Original File - 6658 x 4984 px - 10.20 MB

    This is the C# script I use for the width, height and file size conversions:

    <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();
      }]]>

     

    Can anyone help?

    Cheers, JV

Please Sign in or register to post replies

Write your reply to:

Draft