I'm trying write in two functions in an xslt file that I can use later on to get the width and height of an image that's not in the media section. Here are the functions, they work in a standard .html file but when I try to save in umbraco it gives me the following error. Anyone have any ideas? Or know of an alternative way to get image dimensions from images that aren't in the media section.
Error in XSLT at line 23, char 18 21: 22: function getImgSizeHeight(imgSrc) { 23: >>> var newImg = new Image();<<< 24: newImg.src = imgSrc; 25: curHeight = newImg.height;
Graham -- totally wild... i was JUST wondering how to do this minutes ago :)
anyway, with the help of my good friend Casey Neehouse i was able to simply add to properties to the docType with the upload on it... i am assuming you are talking about imges uploaded via the upload dataType on a content node???
anyway, if you add umbracoWidth and umbracoHeight as Lables to the docType you can then simply access them via xslt with data[@alias='umbracoWidth'] for example...
Yeah I think I remember reading that. Do you know if you also need to change the image upload alias to be 'umbracoFilename'? Or will it still work just adding those labels?
This solves the problem going forward, but I've still got a lot of images already uploaded, so if anyone knows of a way to get those dimensions I'd love to hear it.
if you look at Doug's blog... http://blog.percipientstudios.com i believe his latest post advanced xslt covers getting file size from an image, so extending that should be able to get you what you want from the images...
also, when i did the umbracoWidth, etc. this morning... my upload alias is pageImage and it worked just fine...
I don't think umbracoWidth, umbracoHeight, umbracoBytes or umbracoExtension get's saved for the upload datatype, only for the Image media type. If you want to write inline C# in your xslt macro, you'll need to import the namespaces.
Thanks a bunch guys, lots of great ideas. Bob, I was able to adapt from Doug's blog using c#. Here's what I'm working off of now. Seems to be working for me. I've got some other XSL I'm using to proportionally resize the image based on getting the height and width. Let me know if you'd like to see that also.
Perhaps an easier (and more flexible) way of handling resizing is to use ImageGen (http://our.umbraco.org/projects/imagegen). Tons of options and full docs.
Getting image dimensions
I'm trying write in two functions in an xslt file that I can use later on to get the width and height of an image that's not in the media section. Here are the functions, they work in a standard .html file but when I try to save in umbraco it gives me the following error. Anyone have any ideas? Or know of an alternative way to get image dimensions from images that aren't in the media section.
Error in XSLT at line 23, char 18
21:
22: function getImgSizeHeight(imgSrc) {
23: >>> var newImg = new Image(); <<<
24: newImg.src = imgSrc;
25: curHeight = newImg.height;
<msxsl:script implements-prefix="myFuncs" language="JavaScript">
<![CDATA[
var curHeight;
var curWidth;
function getImgSizeHeight(imgSrc) {
var newImg = new Image();
newImg.src = imgSrc;
curHeight = newImg.height;
return curHeight;
}
function getImgSizeWidth(imgSrc) {
var newImg = new Image();
newImg.src = imgSrc;
curWidth = newImg.width;
return curWidth;
}
]]>
</msxsl:script>
Graham -- totally wild... i was JUST wondering how to do this minutes ago :)
anyway, with the help of my good friend Casey Neehouse i was able to simply add to properties to the docType with the upload on it... i am assuming you are talking about imges uploaded via the upload dataType on a content node???
anyway, if you add umbracoWidth and umbracoHeight as Lables to the docType you can then simply access them via xslt with data[@alias='umbracoWidth'] for example...
hope this helps.
Yeah I think I remember reading that. Do you know if you also need to change the image upload alias to be 'umbracoFilename'? Or will it still work just adding those labels?
This solves the problem going forward, but I've still got a lot of images already uploaded, so if anyone knows of a way to get those dimensions I'd love to hear it.
if you look at Doug's blog... http://blog.percipientstudios.com i believe his latest post advanced xslt covers getting file size from an image, so extending that should be able to get you what you want from the images...
also, when i did the umbracoWidth, etc. this morning... my upload alias is pageImage and it worked just fine...
I don't think umbracoWidth, umbracoHeight, umbracoBytes or umbracoExtension get's saved for the upload datatype, only for the Image media type. If you want to write inline C# in your xslt macro, you'll need to import the namespaces.
Look at http://our.umbraco.org/wiki/reference/xslt/extend-your-xslt-with-custom-functions for an excellent guide.
Thanks a bunch guys, lots of great ideas. Bob, I was able to adapt from Doug's blog using c#. Here's what I'm working off of now. Seems to be working for me. I've got some other XSL I'm using to proportionally resize the image based on getting the height and width. Let me know if you'd like to see that also.
<msxml:script language="CSharp" implements-prefix="myFuncs">
<msxml:using namespace="System.IO" />
<msxml:assembly name="System.Web" />
<msxml:using namespace="System.Web" />
<msxml:assembly name="System.Drawing" />
<msxml:using namespace="System.Drawing" />
<![CDATA[
public String imageHeight(String filePath) {
if ((filePath != null) && (filePath.Length != 0)) {
String localFile = HttpContext.Current.Server.MapPath(filePath);
if (File.Exists(localFile)) {
Image img = Image.FromFile(localFile);
return String.Format("{0:#,###,###.##}",(img.Size.Height));
}
}
return null;
}
public String imageWidth(String filePath) {
if ((filePath != null) && (filePath.Length != 0)) {
String localFile = HttpContext.Current.Server.MapPath(filePath);
if (File.Exists(localFile)) {
Image img = Image.FromFile(localFile);
return String.Format("{0:#,###,###.##}",(img.Size.Width));
}
}
return null;
}
]]>
</msxml:script>
Perhaps an easier (and more flexible) way of handling resizing is to use ImageGen (http://our.umbraco.org/projects/imagegen). Tons of options and full docs.
cheers,
doug.
is working on a reply...