shoes4 icon indicating copy to clipboard operation
shoes4 copied to clipboard

Add text to an image

Open PragTob opened this issue 10 years ago • 2 comments

When you have in image, it'd be preferrable to be able to add text to the image somewhere - we should have a clear way to do this :)

This came in from the mailing list:

I'm building a Shoes app that is a set of 50x50 image tiles. The tiles have different Shoes-generated art in them based on given data (example image below). In some cases I'd like to add simple text to the middle of the image as well, but I can't figure out a way from the manual that allows me to specify a 'font' and add text directly within the image block.

Example image:

 def img_octagon(resp_rgb,orig_rgb,border_rgb)
    @img = image 60,60 do
      translate(5,5)
      strokewidth 0
      fill resp_rgb
      rect(0,0,50,50)

      strokewidth 1
    � � 
      fill orig_rgb
        lw = 12   #line length for each side of the octagon
        lws = lw*Math.sin(45)
        lwx = (50-(lw+2*lws))/2
        shape do
          move_to( lwx, lwx+lws)
          line_to( lwx+lws, lwx)
          line_to( lwx+lws+lw, lwx)
          line_to( lwx+2*lws+lw, lwx+lws)
          line_to( lwx+2*lws+lw, lwx+lws+lw)
          line_to( lwx+lws+lw, lwx+2*lws+lw)
          line_to( lwx+lws, lwx+2*lws+lw)
          line_to( lwx, lwx+lws+lw)
          line_to( lwx, lwx+lws)
        end

        nofill
        strokewidth 3
        stroke border_rgb
        rect(0,0,50,50) 

      ###  WOULD LIKE TO ADD TEXT TO THE IMAGE HERE.
    end
  return @img
 end

PragTob avatar Mar 01 '15 12:03 PragTob

This would require Imagemagick/Rmagick gem to happen, right? unless there is a way in swt that i'm not aware of...

gemantzu avatar Jun 17 '15 09:06 gemantzu

@h1k3n I don't think necessarily, I'd just make an SWT text label positioned over the image so it looks like the image has text. Upside is also, that you could still mark the text.

PragTob avatar Jun 17 '15 17:06 PragTob