Im newbie. What Feed Aggregator available in Rails which can grab one image (largest image) from the source URL?
You could:
parse the feed with SimpleRSS
get the picture's url
store the image with the method described here (using paperclip):
Save image from URL by paperclip
Related
Part 1: I have PDFs, Docs,Docx stored in my S3. When I download them I want them to first be converted to images (png or jpg) and then only download (as images or a thumbnail of images).
How to achieve this ?
Part 2: I have used mini-magick to convert pdf to image and its somewhat working like this:
require "mini_magick"
im=MiniMagick::Image.open("path/to_my_pdf.pdf")
im.format("png", 0)
im.write("some_thumbnail.png")
The problem here is a pdf can have multiple pages and I need each and every page to be converted into image format (may be an array of images) and I am not able to achieve it. I am only able to convert any one of the page of the pdf. Stuck here. Kindly help.
Answer any part of the question as you like. !!
You can do that using RMagick gem as following.
require 'RMagick'
pdf = Magick::ImageList.new("path/to_my_pdf.pdf")
pdf.each_with_index do |page, i|
page.write "#{i}_thumbnail.png"
end
pdf = Magick::ImageList.new(self.checklist_question.resource_file.service_url) do
self.quality = 100
end
This converts the pdf to images but does not get the point on how to save and merge them in pdf again and then upload to active storage.
You could use a different gem like carrier_wave and write the data as explained here: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Upload-from-a-string-in-Rails-3
I am using the stubhub api and would like to use the image_url attribute that is given back for each event object. Currently, the api is returning a string that looks like this for an image:
"stubhub_472291_MortonMeyerson_Concert.png"
I'd like to be able to interpolate this in my rails app so that I have the correct url for each image.
"http://www.stubhub.com/data/venue_maps/#{event.geography_parent}/#{event.image_url}"
I am trying to download an image and displaying it in a view in rails.
The reason why I want to download it is because the url contains some api-keys which I am not very fond of giving away.
The solution I have tried thus far is the following:
#Model.rb file
def getUrlMethod
someUrlToAPNGfile = "whatever.png"
file = Tempfile.new(['imageprependname', '.png'], :encoding => "ascii-8bit")
file.write(open(data).read)
return "#{Rails.application.config.action_mailer.default_url_options[:host]}#{file.path}"
end
#This seems to be downloading the image just fine. However the url that is returned does not point to a legal place
Under development I get this URL for the picture: localhost:3000/var/folders/18/94qgts592sq_yq45fnthpzxh0000gn/T/imageprependname20130827-97433-10esqxh.png
That image link does not point anywhere useful.
My theories to what might be wrong is:
The tempfile is deleted before the user can request it
The url points to the wrong place
The url is not a legal route in the routes file
A am currently not aware of any way to fix either of these. Any help?
By the way: I do not need to store the picture after I have displayed it, as it will be changing constantly from the source.
I can think of two options:
First, embed the image directly in the HTML documents, see
http://www.techerator.com/2011/12/how-to-embed-images-directly-into-your-html/
http://webcodertools.com/imagetobase64converter
Second, in the HTML documents, write the image tag as usual:
<img src="/remote_images/show/whatever.png" alt="whatever" />
Then you create a RemoteImages controller to process the requests for images. In the action show, the images will be downloaded and returned with send_data.
You don't have to manage temporary files with both of these options.
You can save the file anywhere in the public folder of the rails application. The right path would be something like this #{Rails.root}/public/myimages/<image_name>.png and then you can refer to it with a URL like this http://localhost:3000/myimages/<image_name>.png. Hope this will help.
I have the binary data for an image in my controller action. I need to display the image in the view. How can I do this? I'm using Ruby 1.9.2 and Rails 3.0.1.
As coreyward above notes, it's not ideal to be doing this at all. But if you don't have an alternative (really, you probably do), you should look into data URIs.
It depends on what format your binary data is in, but the short version is that you will convert the data to a Base64-encoded string and then build a special URI that starts with data:, followed by the appropriate MIME type, and then the base64 string, and use that as the src attribute in a normal <img /> tag.