dynamic web badge in rails without javascript - ruby-on-rails

I'm trying to create a web badge with user ranking. Intend for it to be used in forums where javascript might not be enabled. I have come across this
<img src='http://www.x.com/vendor.gif.aspx?id=123' style='width:50px; height:50px'/>
from How does one get about making a dynamic web badge using client side javascript?
But i'm using ruby on rails.
Anybody has an alternative method or some hints? Thanks much.

You can create an image using RMagick (uses imagemagick). Use the annotate method to put text in your image.

You don't need JavaScript. Just create a Rails action, which serves the image or whatever you want to be the badge.
<img src="/users/123/badge" ....>
You may want to ask how to create an image with Rails, but that will be a different story ;-)
(ImageMagick comes to mind)

You can create the image with RMagick on the server and then return it to the browser.
Here is a link to an article explaining how to create images.
You'll then need the send_data method in Rails.
I'll try and dig up a link that explains this exactly.

Related

Dynamically render a complex image in Rails with a template

I am trying to add an action to my Rails app rendering a PNG image specific for a given user - some sort of a badge with user picture, name and some standard text. I want to embed the images in emails to be sent out to the users.
The whole badge is fairly complex image, so I am looking for an approach where I can reuse some sort of template image that I just need to update with a user picture and his name.
Would appreciate any examples or ideas on how to do it in rails (what gems can be helpful). Is it easy to have a Rails app to use SVG as a template and then convert it to PNG?
Check out this question
Basically, there are a few different gems you could use to create or manipulate images. Also check ruby toolbox

How do I grab meta data from other websites and display on mine in ruby on rails?

When using FB or Google + I can paste a link of any website into the status update box and it will instant load information about that website with the option of flicking through thumbnail images.
How can I go about achieving this in ruby on rails? All my searches seem to bring up php methods on how to do this.
For grabbing video data info I use the Ruby Open Graph Protocol gem. Is there any thing for grabbing data the way FB and G+ do? If not is there a standard way this is done in rails/ruby, if so.. how is this done?
Kind regards
I think you're looking for something like oembed. I've found a gems for that, so I propose you to take look at it: https://github.com/judofyr/ruby-oembed or https://github.com/embedly/embedly-ruby
You should likely use a gem like http://nokogiri.org/
It allows you to work with a html page just as you would do with jQuery. Very handy.

User customizable backgrounds in Rails 3 App

We are looking to implement User customizable backgrounds in our Rails 3 App. We want to add this facet to the settings page, and from there allow users to upload a JPEG or whatever image file extension it may be, and then make sure it is tiled to fit each Browser window.
How should we go about implementing something like this?
If including code from our repo would assist in gathering a solution, definitely let me know.
Thank you all for your valuable time.
You can make a get request from javascript for a rails resource that is said image and add this as the background-image() for the body. To get the non-public image, this should be useful: https://stackoverflow.com/a/8313398/1040358. To modify the css, this should be useful: https://stackoverflow.com/a/253710/1040358. Good luck! :)

Click on Print gives a screen shot to save in rails3

I may fall under the list of possible duplicates but still i could not find the answer according to my req.In my rails application i have some web pages with a link of print option.
Now what i need is when i click on this print ,i should get a screen shot of the current web page and a popup box to save the image .Is there any plugin available for the same.
Also any queries for code are welcome
Thanx
You could go for phantomJs. Where you can alter the page HTML, manipulate CSS, insert & call javascript snippets, the way you need it.
Good documentation available and also you can find great deal of help in stackoverflow-phantomjs
Regards,
HBK
May i suggest that you use http://www.w3.org/TR/css-print/
if you want to make a screeenshot you have to work with the user env, so i suggest you look at this topic How do I take screenshots of web pages using ruby and a unix server?

How to recreate an image preview from outside websites?

Similar to Facebook's UI, I am attempting at generating a preview image from an external linked website. So that when a user types in a url he is linking, the UI will by default, scan that site for an img and scrape a preview thumb.
Is there a specific name for this technique? Or can anyone point me in the direction of learning this?
Thanks so much!
Its called scraping. There is a library called scrAPI.
Here is a code example http://crunchlife.com/articles/2007/08/13/code-snippet-ruby-image-scraper
There are a couple different options when it comes to page scraping. Another one to check out would be nokogiri, http://nokogiri.org/. You can find tutorials on how to use it at http://nokogiri.org/tutorials.
Instead of grabbing an image from the site, why not grab the image of the entire page? You could make use of a free screenshot service like http://www.websnapr.com/ or http://www.thumbshots.com/ among others. In one application, I use that for my preview image, and use nokogiri to scrape the page title and description. Just an idea.

Resources