Hey,
I’m trying to execute the code below which i have tested and works fine:
<–text.rb–>
p = 2
if p == 1
pos = NorthGravity
elsif p == 2
pos = SouthGravity
else
end
clown = Magick::ImageList.new(“3.jpeg”)
text = Magick::Draw.new
text.annotate(clown, 0, 0, 0, 0, “Text”) {
self.font_family = ‘Helvetica’
self.font_style = Magick::ItalicStyle
self.gravity = pos
self.pointsize = 20
self.stroke = ‘transparent’
self.fill = ‘#0000A9’
self.font_weight = Magick::BolderWeight
}
clown.write(‘text.jpg’)
However when I try to do almost the same in my rails application I get
an error:
TypeError in MainController#addtext
wrong enumeration type - expected Magick::GravityType, got NilClass
Below is the code:
<–main_controller.rb–>
def addtext
@logo = Logo.find(params[:id])
t = params[:text]
c = params[:colour]
s = params[:size].to_f
p = params[:position]
if p == 1
pos = NorthGravity
elsif p == 2
pos = SouthGravity
else
end
@image = File.join(RAILS_ROOT, “public/images/logo.jpg”)
@image = Magick::ImageList.new(@image)
@image = @image.first
text = Magick::Draw.new
text.annotate(@image, 0, 0, 0, 0, t){
self.font_family = ‘Helvetica’
self.font_style = Magick::ItalicStyle
self.gravity = pos
self.pointsize = s
self.stroke = ‘transparent’
self.fill = c
self.font_weight = Magick::BolderWeight
}
@image = @image.write(File.join(RAILS_ROOT, “public/images/logo.jpg”))
{self.quality = 100}
render :action => “edit”
end
p will be either 1 or 2 depending on the value of params[:position] from
the form.
<option value="1">North</option>
<option value="2">South</option>
Any help??
Cheers