Created
March 30, 2011 18:12
-
-
Save kingbuzzman/894916 to your computer and use it in GitHub Desktop.
What took Robert a week to implement i did in 10 minutes...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_dimensions(self, width=None, height=None): | |
| """ | |
| Resize the /images/clients/raw image to whatever dimensions needed, caches the already created images | |
| """ | |
| # default dimentions | |
| height = height or self.image.height | |
| width = width or self.image.width | |
| filename = str(self.image.path) | |
| new_path = filename.replace('/raw/', '/{0}x{1}/'.format(width,height)) | |
| new_relative_path = '/{0}{1}'.format(IMAGES_ROOT.split('/')[-1], new_path.replace(IMAGES_ROOT, "")) | |
| new_dir = '/'.join(new_path.split('/')[:-1]) | |
| # return if the dimension needed is already been created | |
| if os.path.exists(new_path): | |
| return new_relative_path | |
| # create the folder container if it isn't there yet | |
| if not os.path.isdir(new_dir): | |
| os.mkdir(new_dir) | |
| # save the new image | |
| image = ImgObj.open(filename) | |
| image.thumbnail((width,height), ImgObj.ANTIALIAS) | |
| image.save(new_path) | |
| # return the resized image path | |
| return new_relative_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment