# How do I rotate text on inkyphat?

**URL:** <https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257>\
**Category:** Support\
**Created:** [July 9, 2017, 9:48am UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257 "2017-07-09T09:48:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 9, 2017, 9:48am UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/1 "2017-07-09T09:48:02Z")

</div>

I’m working on a thermometer display project with my inkyphat and the last thing I’m missing is text. I can print text alright with the python libs but since the thermometer is displayed in a portrait orientation the text is always angled 90 degrees.

I have found that PIL can perform a rotate and that a possible way for this to work would be to create a temp image, write text to it, rotate and paste into the inkyphat image.

How do I do this? I’m relatively new to Python and programming in general and can’t figure out how to call PIL/Pillow so it allows me access to what the inkyphat library itself is already doing.

Can anyone advise how to maybe achieve this? I would love to see the inkyphat library extended to support this out of the box. Would make text display a lot more versatile.

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 5:04pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/2 "2017-07-09T17:04:12Z")

</div>

Hi there R0ckarong,  
Within the documentation for the Inkyphat hat ([http://docs.pimoroni.com/inkyphat/](http://docs.pimoroni.com/inkyphat/)) it lists `inkyphat.set_rotation(r)` as being part of the default library. I’m afraid I don’t have an Inkyphat to test this with, so I haven’t a clue whether this will work, but it seems it should fulfill your needs?  
Thanks,  
-Picard

---

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 9, 2017, 6:32pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/3 "2017-07-09T18:32:10Z")

</div>

This command rotates the full display (and thus everything on it) by 180 degrees to set off the mounting position (usb on top or bottom). Unfortunately, it does not allow rotating single “elements” that you wish to draw on the display.

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 6:34pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/4 "2017-07-09T18:34:59Z")

</div>

Ah, OK. Thank you for enlightening me.  
I’m not too familiar with epaper displays (well, not at all), so I’m afraid I won’t be able to help much in this matter!  
My apologies.

---

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 9, 2017, 6:37pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/5 "2017-07-09T18:37:07Z")

</div>

Are you proficient in Python? Unfortunately my understanding is not deep enough to figure out how to use modules from the PIL library directly to interact with the display. The current library uses PIL as a basis but I don’t know how to integrate other methods into it for testing.

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 6:43pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/6 "2017-07-09T18:43:59Z")

</div>

If you’re looking to simply use the PIL modules, then it should be as simple as importing PIL and calling the required functions. For example;

`from PIL import Image, ImageDraw`  
``im = Image.open("hopper.jpg")``  
`draw = ImageDraw.Draw(im)`  
`draw.line((0, 0) + im.size, fill=128)`  
`draw.line((0, im.size[1], im.size[0], 0), fill=128)`  
`del draw`  
``  
`# write to stdout`  
`im.save(sys.stdout, "PNG")`

Helpfully provided from [https://pillow.readthedocs.io/en/4.2.x/reference/ImageDraw.html](https://pillow.readthedocs.io/en/4.2.x/reference/ImageDraw.html).  
For any of the other modules, have a look at some of the other examples seen at [https://pillow.readthedocs.io/en/4.2.x/](https://pillow.readthedocs.io/en/4.2.x/)  
Hopefully helpful. :)  
And I’m moderately proficient in Python, though I’d prefer to have an Inkyphat to help properly without constantly asking you whether it works! Though I’m still happy to help as much as I can as long as you can bare my questions.

---

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 9, 2017, 7:04pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/7 "2017-07-09T19:04:02Z")

</div>

I’ve tried this. The problem is that here I don’t know what to pass to “Image.open()” to load the buffer that represents the inkyphat display. The PIL functions are pretty clear to me but without knowing how to write them to the buffer for the display I can’t really use it.

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 7:19pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/8 "2017-07-09T19:19:27Z")

</div>

The closest thing I can find is the `_init_.py` file contained within the library folder of the Inkyphat instillation. It seems to deal with both PIL and the display on their own, namely;

- `from . import il91874`

- `_panel = il91874.IL91874(resolution=(HEIGHT, WIDTH), h_flip=False, v_flip=True)`

- `def show():`  
`"""Display the current buffy on Inky pHAT."""`  
`for y in range(WIDTH):`  
`for x in range(HEIGHT):`  
`_panel.set_pixel(x, y, _image.getpixel((y, x)))`  
`_panel.update()`

These all seem to set up the display and end up writing to the display somehow, but I’m afraid I’m nearing the end of my knowledge of this sort of stuff…  
I’ll try and do some research myself and see if I can turn up anything that might actually help with your specific situation!

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 7:33pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/9 "2017-07-09T19:33:03Z")

</div>

OK, I think I have something here:  
Here is a link to a forum discussion about rotating text in PIL: [https://stackoverflow.com/questions/245447/how-do-i-draw-text-at-an-angle-using-pythons-pil](https://stackoverflow.com/questions/245447/how-do-i-draw-text-at-an-angle-using-pythons-pil)  
_Stenci_ posted a piece of example code which should, in theory, allow you to rotate your text to the desired angle.  
After that, all you should have to do is use the `inkyphat.set_image()` in order to update your screen frame with `image1` every however-long-you’d-like-your-FPS-to-be and wallah!  
This solution causes a lot of issues though, like how to preserve not only the text but the thermometer as well, and the ridiculous loop you would potentially need in order to update the text every time you get a new value.  
Looking at how complex this is now, it’s probably why Gadgetoid didn’t include it in the original `inkyphat.text()` function!  
Have a go at just producing some rotated text using PIL and see if you can get any progress.

---

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 9, 2017, 7:58pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/10 "2017-07-09T19:58:19Z")

</div>

I played around with this exact thread solution two days ago and managed to  
get a blank box drawn on top of my display but I didn’t manage to remember  
what I did to make that work.

---

<div class="post-metadata">

**Author:** ![RaspberryPicardBox](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/raspberrypicardbox/32/7454_2.png) [@RaspberryPicardBox](https://forums.pimoroni.com/u/RaspberryPicardBox)\
**Post date:** [July 9, 2017, 8:09pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/11 "2017-07-09T20:09:39Z")

</div>

You appear to have me at a loss…  
I’ll certainly keep trying to figure out some way of getting this working (probably by getting an Inkyphat sometime soon), but I think your best bet now will be that someone with more experience from the Pimoroni team like @Gadgetoid will be able to help!  
I’ll be sure to keep you up to date with any ideas I come up with in the near future, but I think it’ll take more than my average time span to reply.

---

<div class="post-metadata">

**Author:** ![r0ckarong](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/r0ckarong/32/2763_2.png) [@r0ckarong](https://forums.pimoroni.com/u/r0ckarong)\
**Post date:** [July 21, 2017, 5:59pm UTC](https://forums.pimoroni.com/t/how-do-i-rotate-text-on-inkyphat/5257/12 "2017-07-21T17:59:26Z")

</div>

Btw. I got a response on GitHub and will try as soon as I get my inky back.

[https://github.com/pimoroni/inky-phat/issues/3](https://github.com/pimoroni/inky-phat/issues/3)
