Could not generate clear text of small size
Could not generate clear text of small size
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")
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")
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Could not generate clear text of small size
Try changing gc.stroke('black') to gc.fill('black')
Pete
Pete
Re: Could not generate clear text of small size
Hi, Pete.el_supremo wrote:Try changing gc.stroke('black') to gc.fill('black')
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')
#2 stroke('black')
#3 both
fill('black')
stoke('black')
but I need smth like this (handmade:)
Re: Could not generate clear text of small size
How about this?
The image has been scaled 800% for clarity:
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"
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Could not generate clear text of small size
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?
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?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Could not generate clear text of small size
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
Yep, me too.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.
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
One note more.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
Thank you for your help!
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
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=12zloy wrote:Hi, rmagick!
Yes, it works!! I
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.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.
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 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!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Could not generate clear text of small size
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.zloy wrote:Yep, me too.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.
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?
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Could not generate clear text of small size
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...
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!
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
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
the first two are 'magick' defining this as a psf1 font.0000000 54 4 2 16
0000004
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:
-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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Could not generate clear text of small size
Ok, I bookmarked that forum too!rmagick wrote: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=12zloy wrote:Hi, rmagick!
Yes, it works!! I
Yepp, now I see Thank you for your time. Bye!rmagick wrote: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.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.
Here's the test program that I used: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.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 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
Hi, Anthony!anthony wrote:Thinking about my last post..
...
Now if we can actually use such fonts directly in IM
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!