Hey, I just managed to install ImageMagick and the RMagick gem for rails. But I''m not sure how to run the scripts from the documentation. For example: 1. require ''RMagick'' 2. include Magick 3. 4. cat = ImageList.new("Cheetah.jpg") 5. cat.display 6. exit Does this go into the controller or view?? Seems simple but I''m new to this woudl appreciate any help? Cheers -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First off, cat.display probably won''t work. What you will need to do is something like this: These go near the end of config/environment.rb: require ''RMagick'' include Magick These go in a controller action, say "show_cat": def show_cat cat = ImageList.new("Cheetah.jpg") image = cat.first # first image frame in the image list img.format = ''JPG'' # force conversion to jpeg if needed send_data(img.to_blob, { :type => ''image/jpeg'', :filename => ''Cheetah.jpg'', :disposition => "inline" }) end I believe that send_data is a "show stopper" in that it does not render a template once you use it. At least I don''t have a show_cat.rhtml or other type of file for it to render. Note that this method could use some error checking to make certain that an image is actually loaded. I also do this in the same controller, before calling send_data(): # # Set expiration time, in hopes some of these can be cached. # cache_days = 1 expires_header = DateTime.now.new_offset(0) + cache_days age_seconds = cache_days * 24 * 60 * 60 headers[''Pragma''] = ''public'' headers[''Cache-Control''] = "public max-age=#{age_seconds}" headers[''Expires''] = expires_header.strftime(''%a, %d %b %Y %H:%M:%S GMT'') This lets the image be cached. If you use unique URLs for each of your images, you can get away with this. --Michael --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok thanks. So to display the images in the view do I just call the cat variable? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t think you understand how images work in html. To display an image, you use the standard <img src="http://host/controller/action/id" /> html tag. This calls your controller with the action you want. For instance, I have a "avatar_img_tag" helper action which generates image tags of the form: <img src="/avatar/show/1" /> for me. When this html is processed by a browser, it will make another request to your rails code to retrieve the image itself. That controller has an action, "show", which calls send_data. You cannot really use the image data directly in your view; you must use send_data to send the image data. --Michael --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Michael, Thanks for your info., but I''m still kind of confused. Sorry I''m still new to this. Say for example I had something below, how would I display the rotated image in the view (edit.rhtml)? def edit @image = Magick::ImageList.new("/home/Desktop/clown.jpg") @image = @image.first @image = @image.rotate(90) @image = @image.write("/home/Desktop/clown.jpg") end Cheers -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/17/07, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> def edit > @image = Magick::ImageList.new("/home/Desktop/clown.jpg") > @image = @image.first > @image = @image.rotate(90) > @image = @image.write("/home/Desktop/clown.jpg") > endAt that point, after the @image.write part (remove the @image = part of that, btw) you have written it to a file. In your edit.rhtml file, you would say something like : <img src="<% url_for :controller => :imageview, :action => show, :file => ''clown.jpg'' %>"/> and then in your controller, put something like the code I sent previously that calls send_data() or send_file(). Just be careful using pathnames -- remove all cases of .. from them or you''ll be burned. Note that one "hit" to your server CANNOT both display HTML AND IMAGE CONTENT. You have to do this in two steps. --Michael --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry I have got another question. I''m using the attachment_fu plugin to upload and display images. The code below works where my image (stored on file system) is displayed in the view. However, when I add the following line: @image = Magick::ImageList.new(@image) I get an error: Magick::ImageMagickError in MainController#edit unable to open image `/config/..//logos/0000/0001/300.jpg'': No such file or directory <--code--> <-- controller --> def edit @logo = Logo.find(params[:id]) @image = "/#{RAILS_ROOT}/#{@logo.public_filename}" end <-- view --> <table border="1"> <tr> <th>Logos</th> </tr> <tr> <td> <%= image_tag(@image) %> </td> </tr> </table> <p> <%= link_to ''Rotate'', :action => ''rotate'' %> <p> <%= link_to ''Back'', :action => ''all'' %> I don''t understand why, because the path to the file is correct. Any suggestions? Cheers -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I am trying to install RMAgick but just cant seem to get ImageMagick working. (ubuntu) Can you perhaps tell me what gems (including version numbers) you have installed and in which order. The actuall links to the gems you installed to get RMagick working would be a blessing. Sorry for putting this question here, but you guy''s probably all got this working with ease. Thanks in Advance Scott A S wrote:> > > Sorry I have got another question. > > I''m using the attachment_fu plugin to upload and display images. The > code below works where my image (stored on file system) is displayed in > the view. However, when I add the following line: > > @image = Magick::ImageList.new(@image) > > I get an error: > > Magick::ImageMagickError in MainController#edit > > unable to open image `/config/..//logos/0000/0001/300.jpg'': No such file > or directory > > <--code--> > > <-- controller --> > def edit > @logo = Logo.find(params[:id]) > @image = "/#{RAILS_ROOT}/#{@logo.public_filename}" > end > > <-- view --> > <table border="1"> > <tr> > <th>Logos</th> > </tr> > > > <tr> > <td> > <%= image_tag(@image) %> > </td> > </tr> > > > > </table> > > <p> > > <%= link_to ''Rotate'', :action => ''rotate'' %> > > <p> > > <%= link_to ''Back'', :action => ''all'' %> > > I don''t understand why, because the path to the file is correct. Any > suggestions? > > Cheers > -- > Posted via http://www.ruby-forum.com/. > > > > >-- View this message in context: http://www.nabble.com/RMagick%3A-How-to-run-scripts-in-rails-tf4626597.html#a13332808 Sent from the RubyOnRails Users mailing list archive at Nabble.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---