Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103785
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Request More Help With XBM Image |
| Date | Tue, 01 Mar 2016 09:56:56 +0100 |
| Organization | None |
| Lines | 45 |
| Message-ID | <mailman.60.1456822634.20602.python-list@python.org> (permalink) |
| References | <8rKdnb6SKYLRIEnLnZ2dnUU7-f3NnZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de /iVFMy4sTX8MDig8SPZHUgSiRiL9K6V6BoBZczo8yKxA== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'filename': 0.07; 'seemed': 0.07; 'command.': 0.09; 'file-like': 0.09; 'filename,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stdout': 0.09; 'subject:Help': 0.10; 'output': 0.13; 'argument': 0.15; 'file,': 0.15; 'eliminating': 0.16; 'err': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:More': 0.16; 'xbm': 0.16; 'wrote:': 0.16; 'deleted.': 0.18; 'tells': 0.18; 'runs': 0.18; 'variable': 0.18; 'pipe': 0.22; 'import': 0.24; 'plain': 0.24; 'script': 0.25; 'header:User- Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'external': 0.27; 'least': 0.27; 'question': 0.27; 'object,': 0.27; 'actual': 0.28; 'accepts': 0.29; 'convert': 0.29; "i'm": 0.30; 'work.': 0.30; 'code': 0.30; 'utility': 0.33; 'open': 0.33; 'file': 0.34; 'text': 0.35; 'path': 0.35; 'text.': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'display': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'why': 0.39; 'sure': 0.39; 'format': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'complete': 0.63; 'python-list': 0.66; 'here': 0.66; 'direct': 0.68; 'bitmap': 0.84; 'otten': 0.84; 'subject:With': 0.93; 'technique': 0.93; 'mr.': 0.99 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8788.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103785 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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