This might be simple question.
How to get different renditions of an image in jsp ?
For example
<img src"/content/dam/travel/Desert.png" />
image has 48x48 and 140x100 etc renditions. How to access these in the component jsp ?
I appreciate the help!
Thank you,
Sri
You can do next on jsp page of your component:
<%#include file="/libs/foundation/global.jsp" %>
<%
ResourceResolver resolver = slingRequest.getResourceResolver();
AssetManager assetManager = resolver.adaptTo(AssetManager.class);
Asset asset = assetManager.getAsset("/content/dam/travel/Desert.png");
List<Rendition> renditionList = asset.getRenditions();
//Now iterate through the renditionList to get the absolute path of each renditon for the specified asset
eachRendition.getPath();
%>
If you open an asset in the DAM, you can see the renditions on the right hand side. If you double click them, they will open in a new tab/window where you can see the direct url. In your case I'd guess the urls would be:
<img src"/content/dam/travel/Desert.png/jcr:content/renditions/cq5dam.thumbnail.48.48.png" />
<img src"/content/dam/travel/Desert.png/jcr:content/renditions/cq5dam.thumbnail.140.00.png" />
If you want custom rendition :
Go on http://<author_ip>:4502/cf#/conf/global/settings/workflow/models/dam/update_asset.html
Double click on Process Thumbnails.
In Thumbnails section you can see default rendition :
140:100:false
48:48:false
319:319:false
Below, you can add new rendition on Add Item .
Do not forget to save after editing.
Related
I have a _layout.cshtml which contains everything but the page-specific body of the website. Within this layout I have a header that looks like this:
<div id="header">
<img src="Content/Images/header.jpg" />
</div>
The navigation menu consists of a few ActionLinks that redirect me to the corresponding view.
My problem is that whenever I navigate to a page that is NOT the homepage, the header disappears. I can't see why this would happen, because every _layout is the same, right?
Thank in advance.
Use <img src="#Url.Content("~/Content/Images/header.jpg")" />
Well it looks like I used some wrong pathing. The following change in code fixed the problem:
<div id="header">
<img src="../Content/Images/header.jpg" />
</div>
The child views need an indication that they need to search in the parent folder.
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root. In your case use <img src="~/Content/Images/header.jpg" />
I'm programmatically (server-side) creating an Image object after my user chooses some value from a combonox.
I want to embed this image back into the aspx page at runtime, without saving it to disk or database.
So how can I do this? I tried to use memory stream, and send the image with response object, but than I only saw the image - it had overwritten the entire page.
Thanks...
Create the Handler and request it via:
<img src="Image.ashx?ID=myImageId" alt="text here"/>
<asp:Image runat="server" ImageUrl="~/Image.ashx?ID=myImageId" />
You could base64 encode the data and write it to the image data.
Like this:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">
For this you will have to render the img tag yourself.
This way you don't have to write your image to a file on the server. It is sent from memory directly to the client browser.
Refer: Data URI schemes
Note this does not work with IE6.
Do something like this
<img src="yourimagegeneratingpage.aspx?query=value" />
When this image will be loaded it will generate a request to your page (yourimagegeneratingpage.aspx) and that page would respond with the image which will be shown by this img control.
Suppose this scenario. On my Default.aspx, I insert a context (WebForms), called MyContext.ascx, that load an image. So the path would be :
<img src="/images/hello.gif" />
Well. Now, I'd like to insert the same context on another .aspx page, that is in another forlder, such as /myfolder/MyPage.aspx
Than, the path of the image now should be :
<img src="../images/hello.gif" />
How you can see, I can't manage two different path for the same context. So, is there a way (symbol) to call the virtual-path of my application? Without using my own function as
<img src="<%=MyUtilities.GiveVirtualPath%>/images/hello.gif" />
which is boring. Who know?
Put your images in the root of your web-site (and inside a resources/styles/themes folder).
You can use the tilde ~ to indicate the root of your site. All your pages will refer to that. If you're using server side controls you do not even need to use the ResolvePath() method (in your example you should use it, if for example you wrote asp:image ImageUrl="" you do not need to. From MSDN.
I have a hyperlink that in certain cases I want to change to show a jquery popup, but I'm having a strange problem when doing it on a master page. The following works in a regular page:
hyp1.NavigateUrl = "#notificationPopup";
Which renders as:
<a id="ctl00_hyp1" href="#notificationPopup">Example</a>
This is exactly what I want. The problem is with the exact same code on a hyperlink on the master page it renders as:
<a id="ctl00_hyp1" href="../MasterPages/#notificationPopup">Example</a>
It looks like it might be running the navigateUrl through ResolveClientUrl() or something when I'm setting it on the master page. I've tried swapping the <asp:hyperlink for a <a href runat=server, but the same thing happens.
Any ideas?
There is a note on MSDN Control.ResolveClientUrl method description.
The URL returned by this method is
relative to the folder containing the
source file in which the control is
instantiated. Controls that inherit
this property, such as UserControl and
MasterPage, will return a fully
qualified URL relative to the control.
So the behavior of master page in your exampe is fully predictable (although this is not a very comfortable to work with). So what are the alternatives?
The best one is to set the <a> as a client control (remove runat="server"); should work like a charm even in a master page:
Example
In the case if this control should be server side only: you could just build an URL from your code behind by using UriBuilder class:
UriBuilder newPath = new UriBuilder(Request.Url);
// this will add a #notificationPopup fragment to the current URL
newPath.Fragment = "notificationPopup";
hyp1.HRef = newPath.Uri.ToString();
Create a hidden field on your form and set the value to where you want to navigate / the url of the hyperlink instead of the hyperlinks navigate url. Then call the onclick method of the hyperlink in javascript and set the hyperlink there before the browser does the actual navigation.
<html><head><title></title></head>
<script type="text/javascript">
function navHyperlink(field)
{
field.href = document.getElementById('ctl00_hdnHypNav').value;
return true;
}
</script>
<input type="hidden" id="hdnHypNav" value="test2.html" runat="server"/>
<a href="" onclick="navHyperlink(this);" >click here</a>
</html>
Code behind would be:
hdnHypNav.value = "#notificationPopup";
You could also just try setting the url after the postback with below code, i.e. replace your code behind line with this one but I am not sure if it will work...
ScriptManager.RegisterStartupScript(this,this.GetType(),"SetHyp","$('ctl00_hyp1').href = '#notificationPopup';",True)
I found another way to solve the problem.
hyp1.Attributes.Add("href", "#notificationPopup");
Seeing as the whole reason I replaced my static hyperlink with a runat="server" one was to benefit from automatic resource-based localization, none of these answers served my needs.
My fix was to enclose the hyperlink in a literal:
<asp:Literal ID="lit1" runat="server" meta:resourcekey="lit1">
Example
</asp:Literal>
The downside is if you need to programmatically manipulate the link, it's a bit more annoying:
lit1.Text = String.Format("Example", HttpUtility.HtmlAttributeEncode(url));
In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
Now I want to display it on my datalist. But it is not showing any image. It is might be the case because it is expecting the Image URL to be ~/Folder/abc.jpg
Then how to show the image on the asp.net page when I have image URL, which control I need to use and how?
Do you see little red X instead of an image?
If so, right click it --> Properties (IE) to see the URL it's referring to.
Might give us hint on what's going on. :)
If you are getting the image from the database in for the form xzy.com/1009/image1.jpg but want to add the http:// then your code should be
<asp:Image ID="imgmain" runat="server" ImageUrl='<%#String.Format("http://{0}", Eval("Image"))%>' Width="80" Height="80" />