Sorry, my bad. I always hit reply without checking... it is not the
first time did that,

Here is the solution for the list sake:

""" trim image """
import StringIO, Image
imgdata = StringIO.StringIO()
fig.savefig(imgdata, dpi=300, format='png')
imgdata.seek(0)
im = Image.open(imgdata)

def trim(im, border):
  from PIL import ImageChops
  bg = Image.new(im.mode, im.size, border)
  diff = ImageChops.difference(im, bg)
  bbox = diff.getbbox()
  if bbox:
      return im.crop(bbox)
  else:
      # found no content
      raise ValueError("cannot trim; image was empty")

im = trim(im,'white')
im.show()


The StringIO trick is a copy-and-paste from the matplotlib faq. And the
trim function I got from here:

http://mail.python.org/pipermail/image-sig/2008-July/005092.html


Thanks for the discussion, I learned a lot abouth the Agg backend.


BTW: What I meant by limitation is the fact that Agg has no GUI like the
nice QT window I was using before. The users of this script have no
experience with scripting languages and enjoyed choosing the format and
filename using a GUI interface.

In addition, PIL's show() use an external linux program "xv". In the end
I wanted to eliminate one external linux program (Imagemagik convert)
but ended up with another one...

Best, Filipe

On 04/06/2010 05:01 PM, Friedrich Romstedt wrote:
> 2010/4/5 Filipe Fernandes <ocef...@gmail.com>:
>> Thanks a lot. In the end the "StringIO-solution" worked fine. The only
>> limitation is that this works only for the Agg backend.
>> [...]
> 
> I'm happy to hear this.  As far as I know, using the Agg backend is
> not a limitation, because it provides fully anti-aliased output.
> Besides being available on all platforms (?).
> 
> Let me make a small hint: The matplotlib-users mailing list is
> configured that by default replies go to the sender only, not to
> matplotlib-users, so maybe you want to let the list know about your
> solution?
> 
> Anyway I'm happy for your Thanks,
> so thanks too,
> Friedrich

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to