Create image, send to rails

M

macaco

[Note: parts of this message were removed to make it a legal post.]

Hi, I'm new to this language, so any help will be welcome.

I'm trying to create images at random, not a problem with this, and I can do
it on ruby alone saving the image to the filesystem and watching it later on
a viewer.

Buy when I try to use RoR, like creating the image on the fly, not saving it
to the filesystem, and presenting it on the browser.... well, i get
confused. All I can do so far, it's to show the image i have generated on
ruby before.

btw, i'm using RMagick to do the trick.
 
B

Bira

Hi, I'm new to this language, so any help will be welcome.

I'm trying to create images at random, not a problem with this, and I can do
it on ruby alone saving the image to the filesystem and watching it later on
a viewer.

Buy when I try to use RoR, like creating the image on the fly, not saving it
to the filesystem, and presenting it on the browser.... well, i get
confused. All I can do so far, it's to show the image i have generated on
ruby before.

btw, i'm using RMagick to do the trick.

You can probably use send_data in your controller for this.

http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000229
 
M

macaco

[Note: parts of this message were removed to make it a legal post.]

You can probably use send_data in your controller for this.

http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000229
Thanks, that was helping, but as I was having troubles with rmagic and
windows, i decided to switch to linux

problem is, after i installed everything listed on
http://rmagick.rubyforge.org/install-linux.html, trought apt-get on debian,
once I try to run the gem, this is what I get:

*macaco@ig88:/devel/rtst$ sudo gem install rmagick -r
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb install rmagick -r
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1


Gem files will remain installed in /var/lib/gems/1.8/gems/rmagick-2.0.0 for
inspection.
Results logged to /var/lib/gems/1.8/gems/rmagick-2.0.0
/ext/RMagick/gem_make.out*

Any help?
 
J

Juan Matías

It seems that you don't have building tools, try installing ruby1.8-dev and
build-essential, libgraphicsmagick1-dev packages.

Juan Matias


9
Thanks, that was helping, but as I was having troubles with rmagic and
windows, i decided to switch to linux

problem is, after i installed everything listed on
http://rmagick.rubyforge.org/install-linux.html, trought apt-get on
debian,
once I try to run the gem, this is what I get:

*macaco@ig88:/devel/rtst$ sudo gem install rmagick -r
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb install rmagick -r
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1


Gem files will remain installed in /var/lib/gems/1.8/gems/rmagick-2.0.0fo= r
inspection.
Results logged to /var/lib/gems/1.8/gems/rmagick-2.0.0
/ext/RMagick/gem_make.out*

Any help?



--=20
=ABQuien nunca ha cometido un error nunca ha probado algo nuevo.=BB
 
M

macaco

Thanks Juan Matias, but it was a little more trickier, had to download the
ImageMagick from ftp://ftp.imagemagick.org/pub/ImageMagick/ because debian
gutsy only have the 6.2.4 version, but ruby works with 6.3

anyway, I have this in my controller:

class GenerateController < ApplicationController
require 'RMagick'
include Magick
def index
end

def generate
render :text =3D> "<h1>hello world</h1><img src=3D'/generate/img/1' />"
end

def img
imgl =3D Magick::Image.new(100, 100) { self.background_color =3D 'red' =
}
img.format =3D 'JPG'
send_data(imgl.to_blob, {:type =3D> 'image/jpeg', :disposition =3D>
'inline'})
end

end

but I get this error in the browser:

SystemStackError in GenerateController#img
stack level too deep


RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Ful=
l
Trace
/devel/rtst/app/controllers/generate_controller.rb:13:in `img'
/devel/rtst/app/controllers/generate_controller.rb:13:in `img'

Any help?
 
J

Juan Matías

def img
imgl =3D Magick::Image.new(100, 100) { self.background_color =3D 'red' }
img.format =3D 'JPG' <<<--------- img.format =3D 'JPG or imgl.format =3D=
'JPG'
?
send_data(imgl.to_blob, {:type =3D> 'image/jpeg', :disposition =3D>
'inline'})
end

Thanks Juan Matias, but it was a little more trickier, had to download th= e
ImageMagick from ftp://ftp.imagemagick.org/pub/ImageMagick/ because debia= n
gutsy only have the 6.2.4 version, but ruby works with 6.3

anyway, I have this in my controller:

class GenerateController < ApplicationController
require 'RMagick'
include Magick
def index
end

def generate
render :text =3D> "<h1>hello world</h1><img src=3D'/generate/img/1' />= "
end

def img
imgl =3D Magick::Image.new(100, 100) { self.background_color =3D 'red'= }
img.format =3D 'JPG'
send_data(imgl.to_blob, {:type =3D> 'image/jpeg', :disposition =3D>
'inline'})
end

end

but I get this error in the browser:

SystemStackError in GenerateController#img
stack level too deep


RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace |
Full
Trace
/devel/rtst/app/controllers/generate_controller.rb:13:in `img'
/devel/rtst/app/controllers/generate_controller.rb:13:in `img'

Any help?

It seems that you don't have building tools, try installing ruby1.8-devand
build-essential, libgraphicsmagick1-dev packages.

Juan Matias


and
http://api.rubyonrails.org/classes/ActionController/Streaming.html#M00022= 9



--=20
=ABQuien nunca ha cometido un error nunca ha probado algo nuevo.=BB
 
M

macaco

Yeah, that was it... i'm sorry for my stupid error

def img
imgl =3D Magick::Image.new(100, 100) { self.background_color =3D 'red'= }
img.format =3D 'JPG' <<<--------- img.format =3D 'JPG or imgl.format = =3D
'JPG'
?
send_data(imgl.to_blob, {:type =3D> 'image/jpeg', :disposition =3D>
'inline'})
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,275
Messages
2,571,382
Members
48,072
Latest member
FaustoBust

Latest Threads

Top