Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103785

Re: Request More Help With XBM Image

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Request More Help With XBM Image
Date 2016-03-01 09:56 +0100
Organization None
Message-ID <mailman.60.1456822634.20602.python-list@python.org> (permalink)
References <8rKdnb6SKYLRIEnLnZ2dnUU7-f3NnZ2d@giganews.com>

Show all headers | View raw


Wildman via Python-list wrote:

> I want to take an image file, convert it to XBM format and
> display it.  Thanks to Mr. Otten I can open and display the
> XBM image without any problems.  The script first calls an
> external program for the image conversion then I can open
> and display it.  Of course, I am left with the XBM file that
> needs to be deleted.  It seemed to me to be a better approach
> to use stdout and pipe thereby eliminating the XBM file
> altogether.  Here is code I have so far but I'm not sure
> what to do next...
> 
> convert = "convert " + fileName + " -resize 48x48! -threshold 55% xbm:-"
> p = subprocess.Popen([convert], stdout=subprocess.PIPE, shell=True)
> xbmFile, err = p.communicate()

Why would you need a shell?

> The variable fileName contains the image file path and name.
> The variable convert contains the complete command.  The last
> argument in the command tells the convert utility to covert
> to an XBM and to direct the output to stdout.  After the above
> code runs xbmFile contains the actual image, which is plain
> text.  (X BitMap (XBM) is a plain text binary image format.)
> 
> My question is how do I take the xbmFile variable and convert
> it to an image object that can be displayed?  The technique
> for displaying an image from a file does not work or at least
> I have not been able to get it to work.

I think Image.open() accepts a file-like object, so

import io
...
command = [
    "convert", fileName,
    "-resize", "48x48!",
    "-threshold", "55%",
    "xbm:-"]
p = subprocess.Popen(command, stdout=subprocess.PIPE)
xbmFile, err = p.communicate()
openImage = Image.open(io.BytesIO(xbmFile))

should work. 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-02-29 15:51 -0600
  Re: Request More Help With XBM Image Peter Otten <__peter__@web.de> - 2016-03-01 09:56 +0100
    Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 11:52 -0600
      Re: Request More Help With XBM Image Peter Otten <__peter__@web.de> - 2016-03-01 19:26 +0100
        Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 12:56 -0600
          Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 18:09 -0600
  Re: Request More Help With XBM Image Christian Gollwitzer <auriocus@gmx.de> - 2016-03-01 20:30 +0100
    Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 14:24 -0600

csiph-web