python下的pychartdir模組的使用

來源:互聯網
上載者:User

python下的繪圖需要import pychartdir模組,可以去http://www.advsofteng.com/index.html下載,根據自己系統的版本進行相應選擇。

下載下來後,並不是標準的安裝,需要進行相關的設定,首先用tar命令解壓了

tar -zxvf chartdir_python_version.tar.gz

找到Python 模組尋找路徑目錄下(即site_packages),此路徑可以通過python -c "import sys;print sys.path" 來擷取,建立一個chartdirector目錄

進入Chartdirector/ lib,將其下所有內容copy到上邊建立的目錄,同時在site_packages下touch一個chartdirector.pth,vim編輯加入chartdirector

進入python,即可:

ystan@debian: pythonPython 2.6.7 (r267:88850, Nov 28 2011, 09:24:44) [GCC 4.3.2] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pychartdir>>> 

try:    from PIL import Imageexcept ImportError:    import Imagetry:    from cStringIO import StringIOexcept ImportError:    from StringIO import StringIO from django.core.files.base import ContentFiledef resize_image(image=None,size=50):    if image.mode != 'RGB':        image = image.convert('RGB')    (w, h ) = image.size    if w != size or h != size:        if w > h:            diff = (w - h) / 2            image = image.crop((diff, 0, w - diff, h))        else:            diff = (w - h) / 2            image = image.crop((0, diff, w, h-diff))        image = image.resize((size, size), Image.ANTIALIAS)        thumb = StringIO()        image.save(thumb, 'JPEG')        thumb_file = ContentFile(thumb.getvalue())    return thumb_file

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.