Page 1 of 1

Creating image from text

Posted: 05 Sep 2019 07:04
by tsolignani
Loving automagic more every day, good morning.

I wonder if there is a way to create an image starting with a certain text, with that text into the image.

On a mac, or Linux, you can use imagemagick from the command line.

I could then use dropbox, hazel, a bash script with imagemagick, then dropbox again to get my image on the phone, but I wonder wether there is a quicker and simpler way with automagic and / or an android app one can automate with automagic.

Thank you.

Tiziano

Re: Creating image from text

Posted: 05 Sep 2019 16:00
by anuraag

Re: Creating image from text

Posted: 05 Sep 2019 17:22
by tsolignani
Thank you, I tried it. I guess I should edit it but Java is beyond me. Maybe some day. Thank you.

Re: Creating image from text

Posted: 06 Sep 2019 06:31
by Desmanto
Creating image is simple, you can use action Save Widget to Image File. That java is for image in notification. You can design the image in the widget. Put the necessary element text there. This is the example of mine, which I design to show on my ticwatch.
Image

You can then use setWidget function to change anything, including the text, color, font size and basically any element. Just go to any script/expression/control UI, tap the function, search setWidget, choose it. You can then choose the widget, and modify any element you want.

Code: Select all

setWidgetElementProperty("Wear Note", "Text_1", "text", "Your Text here");
After that, you can use the action Save Widget to Image File. Choose png or jpg, depends on your content. If mostly text, just use png for better result.

Re: Creating image from text

Posted: 06 Sep 2019 06:52
by tsolignani
Very interesting, I'll give it a try. Would you please post an example flow so that I can work on that? That would be simpler for me. Thank you.

Re: Creating image from text

Posted: 06 Sep 2019 10:41
by Desmanto
Here is the sample flow.
Wear Note to Image.xml
(9.96 KiB) Downloaded 693 times
It contains the widget. The script is to change the text and textsize. Save it to image, then create toast message.

You can add any element to the widget and later change it from the setWidget(). Just use the function button inside script, for easier access to any widget element you need.

Re: Creating image from text

Posted: 06 Sep 2019 14:30
by tsolignani
Magic! Thank you.

Re: Creating image from text

Posted: 06 Sep 2019 14:45
by tsolignani
This is hot. Now I just have to write some code to change text dimension according to text length, since I am going to use it with variuos length texts. Thanks again, that did the trick, I could not imagine widget were so powerful.

Re: Creating image from text

Posted: 06 Sep 2019 15:59
by Desmanto
I have done that already too. When the text is too many, I shrink the text size. Delete the last line for the textsize, and replace it with this.

Code: Select all

//set font size depends on note length
fontsize = newMapFromValues(
0, 24.0,
200, 22.0,
300, 20.0,
400, 18.0,
500, 16.0,
600, 14.0);

len = length(note);
for(i in getMapKeys(fontsize))
  if(len >= i) j = i else break;

setWidgetElementProperty("Wear Note", "Text_1", "textsize", fontsize[j]);
This use a map to put multiple stepping. Change the key and value based on your try and error. The reading start from 0 to the next 200, the font size is 24.0. So if your text length is less than 200, it default to 24.0 (the biggest). As it grows, the font size started to get smaller and smaller.

The code above is longer than if you just use multiple if to check it. But I prefer this way to make it tidy and seems organized. Adding new level of fontsize is also much easier.