Page 1 of 1

Could not generate clear text of small size

Posted: 2008-10-29T03:10:23-07:00
by zloy
Hi there!
I'm studying RMagick graphics manipulation gem (which is ImageMagick adopted to use with Ruby) and I need to put small text of size about 8 to 11 px on pictures. I found that text() method prints quite blurred text. And I could not get clear text chosing different values for methods font, font_family, font_style, font_weigth.

I attached a picture to illustrate blur effect. In the left of it you can see black numbers on grey 2:00 3:00, that RMagick generates for me and in the right you can see black numbers 95,4 84,8 on white as an example of clear text I need RMagick to generate for me.

What can I do to get clear text. Any ideas?

PS
My code:
gc.stroke_width(1)
gc.pointsize(10)
gc.stroke('black')
gc.font_style(Magick::NormalStyle)
gc.font_weight(Magick::LighterWeight)
gc.text(x,y, "12:00")

Image

Re: Could not generate clear text of small size

Posted: 2008-10-29T07:39:43-07:00
by el_supremo
Try changing gc.stroke('black') to gc.fill('black')

Pete

Re: Could not generate clear text of small size

Posted: 2008-10-29T08:27:11-07:00
by zloy
el_supremo wrote:Try changing gc.stroke('black') to gc.fill('black')

Pete
Hi, Pete.
Thank you for the advice! I've just tried. The result is interesting and differs when I use or omit these fill() and stroke() methods calls. Using both fill() and stroke() makes resulting image better.


But I still need better. Take a look at these pictures:
#1 fill('black')
Image

#2 stroke('black')
Image

#3 both
fill('black')
stoke('black')
Image

but I need smth like this (handmade:)
Image

Re: Could not generate clear text of small size

Posted: 2008-10-29T16:16:33-07:00
by rmagick
How about this?

Code: Select all

require 'RMagick'

img = Magick::Image.new(50, 20) {self.background_color = "#c0c0c0" }

gc = Magick::Draw.new
gc.pointsize(10)
gc.stroke('none')
gc.fill('black')
gc.text_antialias(false)
gc.gravity(Magick::CenterGravity)
gc.text(0,0, "12:00")

gc.draw(img)
img.matte = false
img.scale!(8)
img.write "test.gif"
The image has been scaled 800% for clarity:
Image

Re: Could not generate clear text of small size

Posted: 2008-10-29T16:26:54-07:00
by anthony
That works well at pointsizes of 10 and higher, however
IM is also supposed to have the ability to use bitmap fonts such as supplied and used by the X windows displays.

However in various attempts I have been unable to get ANY such bitmap font working. Has anyone any information on this?

Re: Could not generate clear text of small size

Posted: 2008-10-30T07:33:18-07:00
by zloy
rmagick wrote:How about this?

Code: Select all

require 'RMagick'

img = Magick::Image.new(50, 20) {self.background_color = "#c0c0c0" }

gc = Magick::Draw.new
gc.pointsize(10)
gc.stroke('none')
gc.fill('black')
gc.text_antialias(false)
gc.gravity(Magick::CenterGravity)
gc.text(0,0, "12:00")

[/quote]

Hi, rmagick!
Yes, it works!! I've tried to turn antialiasing off and got clear text even without scaling.
Take a look at these pictures ;)
[img]http://www.ruby-forum.com/attachment/2873/1.png[/img]
[img]http://www.ruby-forum.com/attachment/2874/2.png[/img]

Thank you for your help!

Re: Could not generate clear text of small size

Posted: 2008-10-30T08:28:29-07:00
by zloy
anthony wrote:IM is also supposed to have the ability to use bitmap fonts such as supplied and used by the X windows displays.

However in various attempts I have been unable to get ANY such bitmap font working.
Yep, me too.
I tried to use different fonts such as courier.ttf, verdana.ttf, cga40869.fon, wst_engl.fon but I didn't notice any differences in text drawings :(
Ideas?

Re: Could not generate clear text of small size

Posted: 2008-10-30T08:48:02-07:00
by zloy
zloy wrote:Yes, it works!! I've tried to turn antialiasing off and got clear text even without scaling.
Take a look at these pictures ;)
Image
Image

Thank you for your help!
One note more.
I've checked again and found that result defends on both callings
@gc.stroke('transparent').stroke_antialias(false)
@gc.text_antialias = false

the best result (which I showed upper) produced by calling both methods.
calling one of them results in worse text drawings.

Re: Could not generate clear text of small size

Posted: 2008-10-30T14:53:48-07:00
by rmagick
zloy wrote:Hi, rmagick!
Yes, it works!! I
Glad to help. For future reference, while I try to keep up with postings on this forum, typically I'm easier to reach on the RMagick forum at RubyForge: http://rubyforge.org/forum/?group_id=12
zloy wrote: One note more.
I've checked again and found that result defends on both callings
@gc.stroke('transparent').stroke_antialias(false)
@gc.text_antialias = false

the best result (which I showed upper) produced by calling both methods.
calling one of them results in worse text drawings.
Careful. stroke_antialias is not the same as text_antialias, and the text_antialias= annotate attribute is not the same thing as the text_antialias() method. Here's the output you get when you replace text_antialias(false) with stroke_antialias(false). Obviously text antialiasing is still in effect.

Image

Here's the test program that I used:

Code: Select all

require 'RMagick'

img = Magick::Image.new(50, 20) {self.background_color = "#c0c0c0" }

gc = Magick::Draw.new
gc.pointsize(10)
gc.stroke('none')
gc.fill('black')
gc.stroke_antialias(false)
gc.gravity(Magick::CenterGravity)
gc.text(0,0, "12:00")

gc.draw(img)
img.matte = false
img.scale!(8)
img.write "test-stroke.gif"
The text_antialias= attribute setter is used with the annotate method. The text_antialias() method is used when you're creating a drawing with the draw method. You can mix the two sometimes but not always, so you're better off never mixing them.

The RMagick documentation has a little mini-tutorial about drawing and annotating that demonstrates the difference: http://studio.imagemagick.org/RMagick/d ... drawing_on

Don't hesitate to contact me on RubyForge if you have any other questions about RMagick. Good luck!

Re: Could not generate clear text of small size

Posted: 2008-10-30T16:45:47-07:00
by anthony
zloy wrote:
anthony wrote:IM is also supposed to have the ability to use bitmap fonts such as supplied and used by the X windows displays.

However in various attempts I have been unable to get ANY such bitmap font working.
Yep, me too.
I tried to use different fonts such as courier.ttf, verdana.ttf, cga40869.fon, wst_engl.fon but I didn't notice any differences in text drawings :(
Ideas?
If you are using command line add +antialias to use the font as a bitmap. This is what is happening in the previous RMagick examples.


HOWEVER. I find this is unacceptable as the fonts get smaller. These vector fonts are not designed for this and as such they start to skip and leave out specific by nessary pixels.

It would be a LOT better at these scales to be able to switch from a vector font like TTF to a bitmap font for a specific scale such as the X window PCF fonts. Or even linux console fonts, such as "PSF", and "FNT".

IM or more specifically the FreeType library delegate should be able to do this, but I have been unable to get it to work in my command line attempts.

This ability is important for generating clear text at small scales as used for web, and tiny diagrams displayed on computer screens, or even worse the modern mobile phone displays.

Re: Could not generate clear text of small size

Posted: 2008-10-30T17:54:30-07:00
by anthony
Thinking about my last post.. I figured there must be some way for IM to at least extract bitmap images from a simple bitmap font like the linux console font files.

As a FYI...

Using information from page
http://www.win.tue.nl/~aeb/linux/kbd/fo ... ats-1.html

Here is the results..

First get the header of the font...

Code: Select all

  gzip -dc /lib/kbd/consolefonts/default8x16.psfu.gz |
     dd bs=1 count=4 | od -t u1
0000000 54 4 2 16
0000004
the first two are 'magick' defining this as a psf1 font.
the fourth is the number of bytes per character bitmap.
there are 256 character (naturally), so for the above that is
16*256 or 4096 bytes (or rows) or 1 byte each. plus 4 bytes
for the header...

So here is the command to display the font!

Code: Select all

  convert -size 8x4100 MONO:/lib/kbd/consolefonts/default8x16.psfu.gz \
          -chop 0x4 -flop -crop 8x16 +repage  gif:- |
    montage - -background skyblue -geometry +2+2 show:
IM auto-magick-ally un-gzips the file (it sees the '.gz' suffix). and reads the file as a raw bitmap.
-size sets the raw bitmap size that was contained in the image.
-chop then removes the 4 byte (now 4 row) header
-flop mirrors the bitmap the right way around
-crop seperates each character into its own image

The montage then just re-assembles the images into a array
for display.

Now if we can actually use such fonts directly in IM ;-)

Re: Could not generate clear text of small size

Posted: 2008-10-31T04:51:07-07:00
by zloy
rmagick wrote:
zloy wrote:Hi, rmagick!
Yes, it works!! I
Glad to help. For future reference, while I try to keep up with postings on this forum, typically I'm easier to reach on the RMagick forum at RubyForge: http://rubyforge.org/forum/?group_id=12
Ok, I bookmarked that forum too!
rmagick wrote:
zloy wrote: One note more.
I've checked again and found that result defends on both callings
@gc.stroke('transparent').stroke_antialias(false)
@gc.text_antialias = false

the best result (which I showed upper) produced by calling both methods.
calling one of them results in worse text drawings.
Careful. stroke_antialias is not the same as text_antialias, and the text_antialias= annotate attribute is not the same thing as the text_antialias() method. Here's the output you get when you replace text_antialias(false) with stroke_antialias(false). Obviously text antialiasing is still in effect.

Image

Here's the test program that I used:

Code: Select all

require 'RMagick'

img = Magick::Image.new(50, 20) {self.background_color = "#c0c0c0" }

gc = Magick::Draw.new
gc.pointsize(10)
gc.stroke('none')
gc.fill('black')
gc.stroke_antialias(false)
gc.gravity(Magick::CenterGravity)
gc.text(0,0, "12:00")

gc.draw(img)
img.matte = false
img.scale!(8)
img.write "test-stroke.gif"
The text_antialias= attribute setter is used with the annotate method. The text_antialias() method is used when you're creating a drawing with the draw method. You can mix the two sometimes but not always, so you're better off never mixing them.

The RMagick documentation has a little mini-tutorial about drawing and annotating that demonstrates the difference: http://studio.imagemagick.org/RMagick/d ... drawing_on

Don't hesitate to contact me on RubyForge if you have any other questions about RMagick. Good luck!
Yepp, now I see :) Thank you for your time. Bye!

Re: Could not generate clear text of small size

Posted: 2008-10-31T04:58:23-07:00
by zloy
anthony wrote:Thinking about my last post..

...

Now if we can actually use such fonts directly in IM ;-)
Hi, Anthony!
I use RMagick to generate charts from Ruby classes and never used it from shell, but It was interesting to new about such a way of ImageMagick using :)
Wish you good luck!