Creating image from text

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Creating image from text

Post by tsolignani » 05 Sep 2019 07:04

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


User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Creating image from text

Post by tsolignani » 05 Sep 2019 17:22

Thank you, I tried it. I guess I should edit it but Java is beyond me. Maybe some day. Thank you.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Creating image from text

Post by Desmanto » 06 Sep 2019 06:31

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Creating image from text

Post by tsolignani » 06 Sep 2019 06:52

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.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Creating image from text

Post by Desmanto » 06 Sep 2019 10:41

Here is the sample flow.
Wear Note to Image.xml
(9.96 KiB) Downloaded 676 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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Creating image from text

Post by tsolignani » 06 Sep 2019 14:30

Magic! Thank you.

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: Creating image from text

Post by tsolignani » 06 Sep 2019 14:45

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.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Creating image from text

Post by Desmanto » 06 Sep 2019 15:59

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply