Skip to content

Meaning of offset for Image::text() #267

Closed
@olivervogel

Description

@olivervogel

I'm trying to figure out the exact meaning of the values for xoffset and yoffset that you get as part of the result of Image::text().

The documentation says it is the "coordinate of the top edge of the character". So far so good, but I cannot reproduce this value in the results.

For example, I generate the following text and render it on grey background.

use Jcupitt\Vips\BandFormat;
use Jcupitt\Vips\Extend;
use Jcupitt\Vips\Image;
use Jcupitt\Vips\Interpretation;

$text = Image::text('<span foreground="#ff5500">Vips</span>', [
    'fontfile' => './fonts/Impact.ttf',
    'font' => 'Impact 130',
    'rgba' => true,
    'dpi' => 96,
]);

$canvas = Image::black(1, 1)
    ->add(200)
    ->cast(BandFormat::UCHAR)
    ->embed(0, 0, $text->width, $text->height, ['extend' => Extend::COPY])
    ->copy([
        'interpretation' => Interpretation::SRGB,
        'xres' => 96 / 25.4,
        'yres' => 96 / 25.4,
    ])
    ->bandjoin([
        200, // green
        200, // blue
        255, // alpha
    ])
    ->composite($text, 'over', [
        'x' => 0,
        'y' => 0,
    ]);

As a result I get the following image with the offset of x -2 and y 38.

Image

I could still explain the value for the x-offset, as the text is slightly offset from the left edge. However, I cannot understand the value of the y-axis, as the font is rendered without any vertical spacing.

  • Is it the distance for a possible next line? Then why is it not influenced by the spacing option?
  • What is the unit of this value? Is it pixels?
  • Do I have to convert this value for the image resolution?

Many thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions