Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: return xoffset/yoffset when creating text image #3780

Open
AndreKR opened this issue Aug 28, 2023 · 1 comment
Open

Enhancement: return xoffset/yoffset when creating text image #3780

AndreKR opened this issue Aug 28, 2023 · 1 comment

Comments

@AndreKR
Copy link

AndreKR commented Aug 28, 2023

Feature request

What are you trying to achieve?

I'm trying to align multiple texts at their baselines. Some cursory experimentation with pyvips suggests that it might be possible to do this if yoffset was available.

In sharp it is not:

let sharp = require('sharp');

(async function () {
	let image = sharp({
		text: {
		  text: 'Hello'
		}
	});

	console.log(await image.metadata());
})();
{
  format: 'raw',       
  width: 30,
  height: 10,
  space: 'b-w',        
  channels: 1,
  depth: 'uchar',      
  density: 72,
  isProgressive: false,
  hasProfile: false,   
  hasAlpha: false      
}

When you searched for similar feature requests, what did you find that might be related?

"yoffset" appeared in several issue but none were about yoffset.

What would you expect the API to look like?

(await image.metadata()).yoffset

What alternatives have you considered?

-

Please provide sample image(s) that help explain this feature

-

@lovell
Copy link
Owner

lovell commented Aug 29, 2023

Yes, this would make a useful enhancement as libvips calculates the top-left position but this is not yet exposed by sharp. A possible implementation might look something like the following:

// PROPOSED API - NOT YET AVAILABLE
const { info } = await sharp({ text: { ... }).toBuffer({ resolveWithObject: true });
const { textOffsetLeft, textOffsetTop } = info;

@lovell lovell changed the title Get vips xoffset/yoffset from image Enhancement: return xoffset/yoffset when creating text image Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants