mirror of https://github.com/chriskiehl/Gooey.git
2 changed files with 45 additions and 58 deletions
Unified View
Diff Options
@ -1,35 +1,28 @@ |
|||||
''' |
''' |
||||
Created on Jan 20, 2014 |
|
||||
|
|
||||
@author: Chris |
|
||||
|
Utilities for loading, resizing and converting between PIL and WX image formats |
||||
''' |
''' |
||||
|
|
||||
|
import six |
||||
|
from PIL import Image |
||||
import wx |
import wx |
||||
|
|
||||
from gooey.gui.three_to_four import imageFromBitmap, bitmapFromImage |
from gooey.gui.three_to_four import imageFromBitmap, bitmapFromImage |
||||
|
|
||||
|
|
||||
|
|
||||
|
def loadImage(img_path): |
||||
|
return Image.open(img_path) |
||||
|
|
||||
|
|
||||
|
def resizeImage(im, targetHeight): |
||||
|
im.thumbnail((six.MAXSIZE, targetHeight)) |
||||
|
return im |
||||
|
|
||||
def _load_image(image_path): |
|
||||
try: |
|
||||
return wx.Bitmap(image_path) |
|
||||
except: |
|
||||
raise IOError('Invalid Image path') |
|
||||
|
|
||||
|
def wrapBitmap(im, parent): |
||||
|
bitmapData = wx.Bitmap.FromBufferRGBA(im.size[0], im.size[1], im.convert('RGBA').tobytes()) |
||||
|
return wx.StaticBitmap(parent, bitmap=bitmapData) |
||||
|
|
||||
def resize_bitmap(parent, _bitmap, target_height): |
|
||||
''' |
|
||||
Resizes a bitmap to a height of 89 pixels (the |
|
||||
size of the top panel), while keeping aspect ratio |
|
||||
in tact |
|
||||
''' |
|
||||
image = imageFromBitmap(_bitmap) |
|
||||
_width, _height = image.GetSize() |
|
||||
if _height < target_height: |
|
||||
return wx.StaticBitmap(parent, -1, bitmapFromImage(image)) |
|
||||
ratio = float(_width) / _height |
|
||||
image = image.Scale(target_height * ratio, target_height, wx.IMAGE_QUALITY_HIGH) |
|
||||
return wx.StaticBitmap(parent, -1, bitmapFromImage(image)) |
|
||||
|
|
||||
|
|
||||
if __name__ == '__main__': |
if __name__ == '__main__': |
||||
|
Write
Preview
Loading…
Cancel
Save