![]() |
Read and view image.png ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Read and view image.png ? (/thread-32714.html) Pages:
1
2
|
Read and view image.png ? - JohnnyCoffee - Feb-28-2021 I'm having trouble viewing an image.png. ? When using the code below do I get a problem visualization (image with black background and a white square in the center of the image)? Why this error and how can I resolve it using native python features? o_png = open('/imagem.png', 'rb') return o_png RE: Read and view image.png ? - Larz60+ - Feb-28-2021 please attach image. RE: Read and view image.png ? - JohnnyCoffee - Feb-28-2021 (Feb-28-2021, 06:06 PM)Larz60+ Wrote: please attach image. Link figure original : https://drive.google.com/file/d/1B0LEggm...sp=sharing Link figuro error : https://drive.google.com/file/d/1zeh8jeH...sp=sharing RE: Read and view image.png ? - Larz60+ - Feb-28-2021 Please attach image here. Don't make us chase it. I tried both links you provide and get: Quote:Sorry, the file you have requested does not exist. RE: Read and view image.png ? - JohnnyCoffee - Feb-28-2021 (Feb-28-2021, 06:43 PM)Larz60+ Wrote: Please attach image here. Don't make us chase it. Okay, I'll try again : Original Figure : Original Link Error Figure : Error Figure RE: Read and view image.png ? - JohnnyCoffee - Feb-28-2021 (Feb-28-2021, 06:43 PM)Larz60+ Wrote: Please attach image here. Don't make us chase it. Okay, I'll try again : Original Figure : Original Link Error Figure : Error Figure RE: Read and view image.png ? - snippsat - Mar-01-2021 Again the problem is that this is related to web-framework you are building,which you are not mentioning. There is different use case from a web-framework that user just open a image in browser. web-framework serve(not open) static files for eg a folder static/images .Then bind images path to root url,here a example in Flask. In example over the link would be http://127.0.0.1:5000/Joker.png .For low level close to WSGI look what's under Flaskl,Werkzeug Serve Shared Static Files RE: Read and view image.png ? - JohnnyCoffee - Mar-01-2021 (Mar-01-2021, 12:41 PM)snippsat Wrote: Again the problem is that this is related to web-framework you are building,which you are not mentioning. Thanks for the feedback but the framework structure is functional where I can read and view .svg files without any problems! Does this only happen in the case of opening image files? Follow the code below: o_file = open("cloud.png", "rb") o_file = o_file.read() RE: Read and view image.png ? - ndc85430 - Mar-01-2021 You haven't really said what the problem is with that code. All that does is read the bytes. Does it fail in some way? Is something else not working? You don't show what you do after the read, so it's pretty hard to help. Don't make us guess! RE: Read and view image.png ? - JohnnyCoffee - Mar-01-2021 (Mar-01-2021, 03:48 PM)ndc85430 Wrote: You haven't really said what the problem is with that code. All that does is read the bytes. Does it fail in some way? Is something else not working? You don't show what you do after the read, so it's pretty hard to help. Don't make us guess! I didn't get it right, but that's okay, follow the complete code: from wsgiref.simple_server import make_server def hello_world_app(environ, start_response): o_file = open("cloud.png", "rb") o_file = o_file.read() status = '200 OK' # HTTP Status headers = [("Content-type", "image/png; charset=utf-8")] start_response(status, headers) # The returned object is going to be printed return [str(o_file).encode("utf-8")] with make_server('', 8000, hello_world_app) as httpd: # Function -> Imprime no terminal reference print( 'Running Kosmos Application\n' 'Browser Access - http://127.0.0.1:8000\n' 'Crl+c for flow command or Crl+z for stop' ) # Serve until process is killed httpd.serve_forever() |