Topic: Add dynamic text to images

I'm making a website for users where they can customize logos, business cards , etc. For this I need a facility to add dynamic text from text boxes which the user will fill in and the text should then appear on the the selected image. I have been trying to use openlaszlo with rails for this but am so lost how to pass parameters between laszlo and rails. Would appreciate any suggestions of how i could do this.

Cheers

Re: Add dynamic text to images

You can do this with RMagick. http://rmagick.rubyforge.org/portfolio.html

Re: Add dynamic text to images

Hey,

Do you have any experience in using RMagick with rails?

I

Re: Add dynamic text to images

By the error message, it looks like the path to your image is invalid.

Where is the logos directory? In the public folder?
If that's the case, try appending your @logo.public_filename path to the RAILS_ROOT variable.

def edit
  @logo = Logo.find(params[:id])
  image = "#{RAILS_ROOT}/#{@logo.public_filename}"
  image = Magick::ImageList.new(image)
end

Re: Add dynamic text to images

Hey,

Thanks for your help. First of all I had to put another '/' in front of the RAILS_ROOT variable to get the image up, do you know why? If I comment out the RMagick line then the image is displayed in the view. When I don't comment out that line I get an error saying:

Magick::ImageMagickError in MainController#edit

unable to open image `/config/..//logos/0000/0001/300.jpg': No such file or directory

For example the path to an image would be:

.../public/logos/0000/0001/28.jpg


<-- controller -->
def edit
    @logo = Logo.find(params[:id])
    @image = "/#{RAILS_ROOT}/#{@logo.public_filename}"
       #@image = Magick::ImageList.new(@image)
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' %>

Last edited by raj (2007-10-18 05:38:11)

Re: Add dynamic text to images

I noticed the public folder is missing from the path.

..
@image = "/#{RAILS_ROOT}public/#{@logo.public_filename}"
..

Last edited by ericc59 (2007-10-18 05:48:28)

Re: Add dynamic text to images

No that doesn't work instead of displaying the image it displays text. If I remove the public path:

@image = "/#{RAILS_ROOT}/#{@logo.public_filename}"

The image is displayed with the above line.

Now when I add the RMagick line:

@image = Magick::ImageList.new(@image)

But for some reason I get an error:

Magick::ImageMagickError in MainController#edit

unable to open image `/config/..//logos/0000/0001/300.jpg': No such file or directory

I don't understand why, because I can display the image in the view.

Cheers