Scale a Font - Pointsize Problem ... ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
betty1978
Posts: 5
Joined: 2011-11-16T04:43:45-07:00
Authentication code: 8675308

Scale a Font - Pointsize Problem ... ?

Post by betty1978 »

hi all,
I built a online image designer and i have a problem with the pointsize. I have a little preview with a text and a image and i want
to scale the preview in a variable size.

My preview has a fixed width of 370px and i will resize the image to eg. 750px. i use $faktor to calculate the new image:

$faktor = 750 / 370;
$width = $width * $faktor;
$height = $height * $faktor;
$x = $x * $faktor;
$y = $y * $faktor;
$pointsize = $pointsize * $faktor;

This works fine with a image, but when i calculate the pointsize with my $faktor is my text not exactly the same as my preview. The problem ist not directly the pointsize,
because the first line is on the left and the right side okay. At the last line you can the the problem ...


You can see the result on my images:
crop width: 370px
Image

crop width: 750px
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scale a Font - Pointsize Problem ... ?

Post by anthony »

You are not exactly clear about what you are doing. What is your starting point? Why do you want pointsize? Are you actually rendering text onto the image at different sizes?

Note directly scaling pointsize does not generate exactly the same results! Neither does density, though its results is likely to be closer.
See Pointsize, Denisty and the Actual Font Size
http://www.imagemagick.org/Usage/text/#pointsize

If you are actually resizing the image and not simply drawing text, just resize it to the width wanted. (leave out the size attribute you want it to calculate! Hmmm I actually don't have an example of that! Strange! IM will by default calculate the final image size to try and best preserve aspect ratio as much as possible (rounding to an integer pixels image size).

It is always better to scale images smaller, than trying to enlarge images.

If you want to scale exactly with a given scaling factor, and possibly generate sub-pixel edges, you can use -distort for the resize
http://www.imagemagick.org/Usage/resize/#distort
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
betty1978
Posts: 5
Joined: 2011-11-16T04:43:45-07:00
Authentication code: 8675308

Re: Scale a Font - Pointsize Problem ... ?

Post by betty1978 »

Thank you for your answer!
i build a online designer for my customer and they can create and move text over a background. The customer can move an div and i have the x/y coordinates and the
width/height from the div and i create with image magick the text into the div.

This works very well, but 370px is too small and i will create a big preview for the customer in a variable size and later i will print this image.

I can´t create a big image at the background, because image magick working much longer for the 370px preview.

I have testet with density and the result not better. :?
I have selected a pointsize of 22 in my designer(370px) and i create a preview in 750px
The new pointsize is 44.6 and the density is $b = 146
$a = 22 / 72;
$b = 44.6 / $a;

Preview (original)
Image

Image with Pointsize of 44.6 and 72 density
Image

Image with Pointsize of 22 and 146 density
Image

You find the designer on my test site http://xxxxxxxx.de/designer/
click on the right side "Text hinzufügen" and create a new text.
Over the preview is a zoom icon and image magick generate a big preview ....
Last edited by betty1978 on 2011-11-18T00:17:34-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scale a Font - Pointsize Problem ... ?

Post by anthony »

Basically What I said holds true...
Fonts at a different pointsize or density, do not match the same font that is resized.

Fonts are specifically designed to do this so as to produce the best and cleanest looking glyph they can for the specific pixel array they are being rendered to.

This has also been a major pain for vector images, which are specifically designed to be drawn at different densities.

Many times I have added text to an arrow but did not justify the text to the righ point, as as a result, when I printed it the text was no longer alligned with the arrow. The solution in those cases was to use a justified position which was close to the end of the arrow, and let the rest of the text 'resize' around that point. This is another reason why IM needs to separate justification and gravity positioning settings which is currently does not do.


The only way to get fonts to behave in this way is to draw the font at the highest density (say for laser printers, so you get what it prints as) then resize (or scale distort for more exact resize) to the size needed for viewing. The font will not 'look' anywhere near as good, but the alignment between font and other graphical elements (raster or vector) will then be aligned in exactly the same way it would be when finally printed.


WARNING: resize tries to preserve aspect ratios, but is limited to whole pixels, so vertical and horizontal aspect rations will very very very slightly. Also as it is integer aligned you can only position resized test to a whole integer. (the offset of composition).

Distort SRT however can scale (S) the text to sub-pixel boundaries, and even position (translate or T) the center point of the scaling to a sub-pixel location. For precise placement of scaled text (actual scale and location), you will need to use distort.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
betty1978
Posts: 5
Joined: 2011-11-16T04:43:45-07:00
Authentication code: 8675308

Re: Scale a Font - Pointsize Problem ... ?

Post by betty1978 »

Thx, it Works very well with Distort SRT. :D
Post Reply