Grails image url loads but image doesn't load? - image

In grails, images url loads fine but image doesn't display...
def thumbphoto = {
response.setContentType('image/jpeg')
response.setHeader('Cache-control', 'no-cache')
if(params.id){
userId = params.id
}
if(params?.id != null && !(params?.id.empty)){
params.maxWidth?: 50.00
params.maxHeight?: 50.00
response.outputStream << imageProxyService.loadThumbnailImage(params.id, securityService.passwordEncoder(userId.toString()))
}
}
User has many images
This is the gsp view where i am trying to load and display images along with status updates.
<g:each in="${statusList}" status="i" var="status" status="i">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<tr>
<td>
<g:if test="${status.photo != null && !(status.photo.empty)}" >
<img id="profile_photo" src="${createLink(controller:'image', action:'thumbphoto', id:status.photo, params:[maxWidth:50.0,maxHeight:50.0,id:status.id])}" alt="" title="" />
</g:if>
<g:else>
<img id="profile_photo" src="${resource(dir:'images', file:'no_image_blue.gif')}" alt="No Image" width="50" height="50"/>
</g:else>
</td>
<td>${status.id}: ${status.message}</td>
</tr>
</tr>
</g:each>

Install Firebug, and go to the Net tab.
You should see all the HTTP requests and their statuses.
You're likely get a 404 for your image, check its location under your webapps folder...
Again Firebug will give you all the hints and solutions.

Use g:img.
<g:img dir="/image/showImage/9921355add3b115766ad41effdf000db9e461570.jpg" alt=""/>

Related

Generating html with CFSaveContent, images don't display

I'm trying to use cfsavecontent to send an html page (with CSS formatting). However, when I send the variable via cfmail, everything arrives fine, except the images.
<cfsavecontent variable="YourImg">
<table class="table_css">
<tr>
<td>
<p> your image is this:</p>
<img src="/imgs/image.jpg">
</td>
</tr>
</table>
</cfsavecontent>
<cfmail from="email#hotmail.com" to="email#gmail.com" subject="test email" type="html">
test:
<br /><br /><br />
#YourImg#
<br /><br /><br />
</cfmail>
This shows me the HTML table, formatted with the CSS, but the image looks like it is missing. Can anybody explain why?
<cfsavecontent> only saves the generated markup in between the tag into a string. You can <cfdump var="#YourImg#"> and see for yourself.
<cfdocument> can capture the image, but into a pdf file. Doc # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfdocument.html
To attach files to the email, please look into <cfmailparam> # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmailparam.html
Example 2: This view-only example displays an image in the body of an
HTML message.
<cfmail type="HTML"
to = "#form.mailto#"
from = "#form.mailFrom#"
subject = "Sample inline image">
<cfmailparam file="C:\Inetpub\wwwroot\web.gif"
disposition="inline"
contentID="image1">
<p>There should be an image here</p>
<img src="cid:image1">
<p>After the picture</p>
</cfmail>

Session user images load but not images from everyother user? Grails

Images by session or logged in user load and displayed fine but images from users other than session users won't get displayed. note: url for every images load just fine its just images aren't displayed.
Image controller:
def thumbphoto = {
response.setContentType('image/jpeg')
response.setHeader('Cache-control', 'no-cache')
if(params?.id != null && !(params?.id.empty)){
params.maxWidth?: 50.00
params.maxHeight?: 50.00
response.outputStream << imageProxyService.loadThumbnailImage(params.id, securityService.passwordEncoder(userId.toString()))
}
}
query for outputting image and slogan
def statusQuery = """SELECT c.user_account_id as userId, c.status_message as message, c.status_type as profile, se.id, se.photo FROM user_account se, status c
WHERE
c.user_account_id = se.id
GROUP BY se.id, c.user_account_id, c.status_message, c.status_type, se.photo"""
displaying images in gsp:
<g:each in="${statusList}" status="i" var="status" status="i">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<tr>
<td>
<img id="profile_photo" src="${createLink(controller:'image', action:'thumbphoto', id:status.photo, params:[maxWidth:50.0,maxHeight:50.0])}" alt="" title="" />
</td>
<td>${status.id}: ${status.message}</td>
</tr>
You are overwriting id
id:status.photo and params:[id:status.id]
edit:
and not passing userId
try to create link and add userId in it:
<img id="profile_photo" src="${createLink(controller:'image', action:'thumbphoto', id:status.photo, params:[userId:status.userAccount.id, maxWidth:50.0,maxHeight:50.0])}" alt="" title="" />

concdtional img src inside grdiview image template

I m using image template inside a gridview like this
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div1<%# Eval("bank_id") %>');">
<img alt="" id="imgdiv1<%# Eval("bank_id") %>" width="20px" border="0" src="../Images/Plus.gif" />
</a>
</ItemTemplate>
</asp:TemplateField>
here i am using src="../Images/Plus.gif" but i want to set to path conditionaly.like if Eval("bank_id") is -1 then there should no image displayed or path to b set.is there any one help me to set the conditonal image path
you can small trick here. instead of bind your data directly to your image you could call some function that 'll send to it directly the data from DB then in that function you check for that value and based on what you need you return the correct string(correct image src).
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div1<%# Eval("bank_id") %>');">
<img alt="" id='<%#getImageSRC(int.Parse(Eval("bank_id").ToString())) %>' width="20px" border="0" src="../Images/Plus.gif" />
</a>
</ItemTemplate>
</asp:TemplateField>
then in your cs file:
public string getImageSRC(int bankId)
{
if (bankId < 0)
return "";
else
return "/bank-images/" + bankId + ".jpeg";//return here the correct image path
}

making an image link from a db asp.net mvc 4

I have this foreach loop pulling images from my db :
`#foreach (var item in model)
<tr>
<td>
<img width="50" height="50" src="#Url.Action("GetImage", "Product", new { item.ProductId})"/>
</td>
...`
I tried to wrap it in an 'a' tag but all I get is 404's.
<img width="".../>
Any ideas?
an image with a hyperlink is what I'm trying to achieve. You click the
image and you're taken to the edit page.
Okay so suppose you get the image as shown in your question Product.GetImage and then the edit page is called by Product.Edit, you can have this:
<img src="#Url.Action("GetImage","Product")" />

Hiding DIV in TPL file based on if an image exists?

<div><div style="margin-left:67px"><table style="border:1px #80A0BB solid;" padding="5px"><tr><td><img src="{$smarty.const.DOC_ROOT}/images/thumbs/{$link.ID}-300x225.png" alt="" /></td></tr></table></div></div>
I'm trying to hide a div based on if an image exists on my server. How would I check to see if an image exists and hide the div if it doesn't exist? Or is there a better way to do this?
The easiest way is just to use write a function in PHP and then use it in Smarty.
In PHP:
function linkImageExists($link){
//Check to see if image for link exists and return true if it does.
// otherwise:
return false;
}
In Smarty template:
{if linkImageExists($link)}
<div>
<div style="margin-left:67px">
<table style="border:1px #80A0BB solid;" padding="5px">
<tr>
<td>
<a href="{$link.URL|trim}" target="_blank">
<img src="{$smarty.const.DOC_ROOT}/images/thumbs/{$link.ID}-300x225.png" alt="" />
</a>
</td>
</tr>
</table>
</div>
</div>
{else}
{* image doesn't exist *}
{/if}
You may want to consider turning $link into an object and then you can call functions on it, rather than having to use global functions which may producer cleaner code in the future.

Resources