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

Word wrapping Drawing.text #298

Closed
wodim opened this issue Jul 4, 2016 · 4 comments
Closed

Word wrapping Drawing.text #298

wodim opened this issue Jul 4, 2016 · 4 comments

Comments

@wodim
Copy link

wodim commented Jul 4, 2016

I'm not sure this is the appropriate place to ask for this. I'd call it a feature request but I'm going to ask it as a question, because I'm not sure if it actually can be done using Wand as it is now (i.e. I'm missing something). I think ImageMagick can do it itself.

I want to word wrap text to a certain width in pixels with wand.drawing.Drawing.text wand.image.BaseImage.caption is (I think) unsuitable for my needs, as I need the text to have a stroke. By now I'm using textwrap.fill from the standard library as a workaround but, as you can imagine, it's not a perfect solution.

draw = Drawing()
draw.font_size = 100
draw.fill_color = Color('#fff')
draw.stroke_color = Color('#000')
draw.stroke_width = 2
draw.gravity = 'south'
draw.text(0, 0, textwrap.fill(text, 20))
draw(img)

Thanks for Wand by the way, great work.

@andy-io
Copy link

andy-io commented Jul 13, 2017

Any idea of how to do this using draw.text method instead of using caption method ?
@wodim : did you find any other solution ?

@ivanholmes
Copy link

I've run into this issue today. ImageMagick can definitely do it itself.

I might have a look into adding this if I get the time.

@ivanholmes
Copy link

I've just submitted a pull request (#375) to allow a stroke on wand.image.BaseImage.caption.

@emcconville
Copy link
Owner

Following up on this. Currently the drawing class will remain very low-level API. However word-wrapping is often requested. I'm hesitant at attempting & shipping a word-wrap solution as users will often have conflicting behavior requirements (e.g. locale grammar, text/alignment tracking, hyphenation rules/exceptions).

Perhaps, one day, we'll introduce a wand.contrib module that'll hold community driven solutions to common problems; but until then, I've updated the docs to include an example of how one may achieve word-wrapping.

http://docs.wand-py.org/en/latest/guide/draw.html#word-wrapping

Revisions / critiques always welcome on the usage guides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants