On 18 March 2010 18:50, Adam Ziemba <[email protected]> wrote:
>> open('http://chart....') do |chart|
>> File.open('chart.png', 'w') {|f| f.write chart.read }
>> end
>
> This is wonderful, I knew nothing of open-uri. However, I cannot seem to
> get it pull an image. Using the Google link above, which produces a PNG
> image, I get the error "bad URI(is not URI?)".
I think you have two problems, firstly you need to escape the uri,
this seems to work but there is probably a nicer way of doing it:
open("http://chart.apis.google.com/chart#{CGI.escape('?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12')}")
do |chart|
File.open('chart.png', 'w') {|f| f.write chart.read }
end
Unfortunately you do not end up with a png file. If you open the file
with a text editor you will find it is a web page with loads of
javascript. Presumably the javascript generates the png. I think you
need an alternative approach.
Colin
>
> Looking at the API for open-uri, I could not find any information about
> images.
>
> I played around with it, I can beautifully retrieve web pages and save
> them to disk, but what about images?
>
> Thanks for the help!
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.