Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Saving Console Display To An Image
-
HI,
I am sure this is a basic question..
i want the simplest way to save the puzzle generated on the console to be saved as an image.
I tried reading through ImageContext, Image, ctx etc but failed to understand.
Please help..For eg. let's say i want to save this display as an image..
# save display import ui w,h = ui.get_screen_size() view = ui.View(name = 'Grid', bg_color=1) view.add_subview(ui.View(name='left', frame=(0,0,w/3,h/5), bg_color='blue')) view.add_subview(ui.View(name='right', frame=(w*2/3,0,w/3,h/5), bg_color='red')) view.present('sheet')
-
I am just a beginner. I am sure you want something more than my suggestion. But you could snap a picture of the screen with the side button and the home button at the same time and have the screen shot in your photos app
-
# save display import ui w,h = ui.get_screen_size() view = ui.View(name = 'Grid', bg_color=1) view.add_subview(ui.View(name='left', frame=(0,0,w/3,h/5), bg_color='blue')) view.add_subview(ui.View(name='right', frame=(w*2/3,0,w/3,h/5), bg_color='red')) view.present('full_screen') # create image with ui.ImageContext(view.width, view.height) as ctx: view.draw_snapshot() with open('test.png', 'wb') as out_file: out_file.write(ctx.get_image().to_png())
-
This post is deleted! -
@cvp ,
Thank You Very Much, Exactly What I Wanted.. :) -
@ramvee , a small thing that maybe useful, more for debugging use. But you can display a ui.Image in the console by using the show method. I just added one line to what @cvp did in #create image block at the end. It's just useful to know about, if you dont already.
This looks a little more practical if say may the image in one function returning the ui.Image and passing it to other functions to write out the file. But the idea is the same anyway.with ui.ImageContext(view.width, view.height) as ctx: view.draw_snapshot() with open('test.png', 'wb') as out_file: out_file.write(ctx.get_image().to_png()) ctx.get_image().show() # prints the ui.Image to the console
-
@Phuket2 ,
Thank you very much for the tip.
I would also like to thank you for your old post on the same topic at
https://forum.omz-software.com/topic/3401/share-using-draw_snapshot-method
which i saw after i posted this thread.
Sometimes searching is very difficult in this forum. :)
Take Care -
@ramvee , you are welcome. I did remember posting that after seeing this msg. But for sure, @omz, @JonB or @ccc helped me to get to the point to write it. I remember struggling with the ui.ImageContext and after some guidance was able to put that post together. Mind you its all in the docs, but some times even if the docs are well written it can be hard to get the idea.
You are right the forum is difficult to search.
But its worth using some google search tricks to search the forum. Gives you a lot better results. One example "forum search site:forum.omz-software.com ui.ImageContext", there are other syntax's for using googles search methods for sites. I dont really know them.
I have to get back in touch with a user from this forum called @cook. He made a Pythonista forum search browser that you launch from the wrench menu and opens up a browser in a panel in Pythonista. When he was building it, I was helping him, mainly testing it, offering suggestions. The version I have is not 100% polished but still works well enough. He did some things with .js and some other tricks to allow you keep searching google without it shutting you down as google does if you query it too many times through an API. I will try and touch base with him again to see if it actually did more work on it, or see if he is willing for it to be shared so maybe some others could contribute to it. I dont think its rocket science, but there is stuff in there I dont understand. You can also copy the python code blocks to the clipboard.
Seems like Pythonista could use a very polished version of something like this. -
@ramvee said in Saving Console Display To An Image:
HI,
I am sure this is a basic question..
i want the simplest way to save the puzzle generated on the console to be saved as an image.
I tried reading through ImageContext, Image, ctx etc but failed to understand.
Please help..
For eg. let's say i want to save this display as an image..If you want a simple way to save a puzzle generated on the console as an image, you can consider using a programming language or framework that offers image manipulation capabilities. For example, in Python, you can use libraries like Pillow to create and save images easily. First, generate your puzzle on the console, and then use Pillow to capture a screenshot of the console window or create an image representation of the puzzle. You can customize the image's format and save it to a specific location on your computer. This approach provides a straightforward and efficient solution for converting your console-based puzzles into image files for easy storage and sharing.