Fancybox shows blob as string not image (Ruby issue?) - ruby

I am displaying an image obtained from a database (stored as a long blob) in an img tag using the following method:
<img src="http://localhost:3000/show_image/265" />
The show_image function takes the image data from the database and renders it to the img tag using the send_data method.
When applying Fancybox onto the img tag, the data is displayed as BLOB data not the image..
Can anyone suggest a reason why? Or how I can solve this?

1) You have to apply fancyBox to the links (not the images) and the structure should be like this -
<a class="fancybox" href="big_image"><img src="small_image" /></a>
Example - http://jsfiddle.net/CYCeM/.
Well, it is actually possible to have only images, but then you have to use "data-fancybox-href" attribute to specify the large one - http://jsfiddle.net/6ZSWB/
2) Looks like the script would not be able to guess the content type from your hrefs. You have to either -
a) Create links having extension, e.g., "http://localhost:3000/show_image/265.jpg"
b) Set content type for fancybox, example - $('.fancybox').fancybox(type : 'image');

setting :type => "image/jpg" fixed the issue. I looked up the MIME content types and realised it was incorrectly written.

Related

thymeleaf html tag with img file extension wild card

I have a thymeleaf html tag that displays an image but the image could be a jpg or it could be a png.
Example
<img th:src="'http://localhost:8081/'+#{'/images/'}+${image}+'.jpg'"/>
I need to substitute the '.jpg' for a wild card extension so as to display either jpg or png
does anyone know what that piece of code at the end is?
Thanks
I don't think it is possible. Thymeleaf has no way to detect what is the type of the file and the browser need the full path of the file to show it.
I would advice to detect/add the file extension at the same place your set the ${image} value.
For example by converting the "image" variable to an object with "name" and "extension" fields
<img th:src="'http://localhost:8081/'+#{'/images/'}+${image.name}+${image.extension}"/>

How to add and render multiple images/files in typo3 Fluid content element(flux)?

I am using flux and fluid content element for making content editable by user. i added field for image which allows multiple images to upload.
But now i am not able to show these images.
my value of field image is like :
image => 'kip.jpg,772_Visteon_010.jpg'
normally if i have only one value then i can show it by <f:image> or <img src="{image}" /> Tag.
so, anybody have idea how can i display multiple images or files.
Thanks in advance.
you seem to use the old style of image inclusion: comma separated list of names with copies below uploads/.
Then you need to split (https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Split/Index.html) the field and work the resulting array as before.
in the long time you should use FAL, so the handling is a little bit more complex
You should use flux inline fal for multiple images in fluid content element,
below is a syntax for inline fal,
<flux:field.inline.fal name="settings.image" label="Image" />
After that you can render it by following code,
<f:for each="{v:content.resources.fal(field: 'settings.image')}" as="image">
<f:image treatIdAsReference="1" src="{image.id}" title="{image.title}" alt="{image.alternative}"/><br/>
</f:for>
you can find detail in below url,
https://fluidtypo3.org/viewhelpers/flux/master/Field/Inline/FalViewHelper.html
hope this will help you.

How to display uploaded images in pdf using wkhtmltopdf

I am using Carrierwave to upload images in rails4.
In the html view page the image is showing. But, when generating the pdf, from this view, the image is not showing.Instead , a blank box is showing.
From the view, while inspecting the path is showing as below:
<img alt="Small images" src=" http://127.0.0.1:3000/upload_
files/6/student/image/1/small_images.jpg">
The code i used is:
<%=image_tag Student.find(id).image_url(:small) %>
If the image is stored in app/assets/images, then the images will appear.But, i need to upload the image in this location only.
Can u pls help...
Thanks in advance.
I could do it with php Laravel this way >>
<img alt="Small images" src="{{base_path().'path/to'image.jpg'}}">
I have no experiences with Ruby , but try to find something similar.

Insert image into Primefaces editor

I'm using JSF2.2, Tomcat 8 and MySQL DB to create a simple CMS. In my back pages I use Primefaces p:editor to create/edit my page content. I would like to insert an image somewhere into the text. It would be great if I could upload the image and insert it at the current cursor position. Ideally, the image should be saved as a blob, but if it's easier for the implementation it could instead be stored as a local file.
I can see that p:editor already has an option to insert a URL of an image, resulting in the <img> tag in the text. But I would really like the possibility to upload an image from my local drive. I haven't been able to Google anything useful so far.
this is how i did it:
.xhtml:
<p:editor id="editor"
widgetVar="editWidget"
value="#AnnouncementBean.text}" />
<p:fileUpload id="upload"
fileUploadListener="#{AnnouncementBean.uploadListener}"
label="Insert image"
mode="advanced"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
update="editor, growl">
</p:fileUpload>
An in my Backing Bean in the uploadListener after file upload:
String value = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("editor_input");
setText(value + "<img src=\"/uploads/" + result.getName()+"\" />");
RequestContext.getCurrentInstance().update("editor_input");
where "editor_input" referes to the actual form field submitted for the editor (PF adds the_input to the id of your editor)
Notice how I update the editor_input not the actual editor. Only problem now is that the image is appended to the end of the text. sou you must move it manually within the editor
You can use a string to receive the editor (or textEditor) value, then use regex to find all img elements.
This is my code.
String regex="<img src="data:image/(gif|jpe?g|png);base64,([^"]*")[^<>]*>";
Matcher m = Pattern.compile(regex).matcher(your_textEditor_value);
while(m.find()){
String imageFileType=m.group(1);
String imageDataString=m.group(2);
byte[] imageData=Base64.decodeBase64(imageDataString);
}
The imageFileType is your file type, and imageData is data of the file. You can use it to do other thing.

Loading image src using a variable containing base64 data in AngularJS

Loading image using variable containing base64 data in AngularJS
I am trying to find the right way to load a image source from a variable containing base64 encoded image data (for example pulled from a canvas using toDataURL(); ).
At first I just tried it like this:
<img src="{{image.dataURL}}" />
where the image is a scope variable with a variable dataURL containing the base64 data. This is actually working pretty well, the only problem is that I get a 404 error in my console. Something like this:
GET http://www.example.com/%7B%7Bimage.dataURL%7D%7D 404 (Not Found)
Not so pretty. When I tried a more angular style solution like this:
<img data-ng-src="image.dataURL" />
the images are not loading at all.
I made a fiddle which you can find HERE
Any suggestions how to get rid of this error in my console?
EDIT:
Gruff Bunny was right. This <img data-ng-src="{{image.dataURL}}" /> is working...
Working solution can be found HERE
The content of the ng-src needs to be interpolated: Try this:
<img data-ng-src="{{image.dataURL}}"/>
I admit I spent way too much time trying to fix similar problem,
my problem was I had extra brace here (see three braces at end):
ng-attr-src="{{aad.form.imageBase64Temp}}}"

Resources