Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read and view image.png ?
#1
Question 
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
Reply
#2
please attach image.
Reply
#3
(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
Reply
#4
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.
Reply
#5
(Feb-28-2021, 06:43 PM)Larz60+ Wrote: 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.

Okay, I'll try again :

Original Figure : [Image: view?usp=sharing]
Original Link

Error Figure : [Image: view?usp=sharing]
Error Figure
Reply
#6
(Feb-28-2021, 06:43 PM)Larz60+ Wrote: 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.

Okay, I'll try again :

Original Figure : [Image: view?usp=sharing]
Original Link

Error Figure : [Image: view?usp=sharing]
Error Figure
Reply
#7
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
Reply
#8
(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.
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

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()
Reply
#9
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!
buran likes this post
Reply
#10
Thumbs Up 
(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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read from image with several languages using inage_to_string()? EvilSnail 0 2,109 Nov-13-2021, 03:11 PM
Last Post: EvilSnail

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020