-
Notifications
You must be signed in to change notification settings - Fork 77
[SVCS-407] Adding support for .psd files to MFR #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import os | ||
| import imghdr | ||
| import warnings | ||
|
|
||
| from PIL import Image | ||
| from psd_tools import PSDImage | ||
|
|
||
| from mfr.core import extension | ||
| from mfr.extensions.image import exceptions | ||
|
|
@@ -23,7 +25,16 @@ def export(self): | |
| 'max_size_h': max_size[1], | ||
| }) | ||
| try: | ||
| image = Image.open(self.source_file_path) | ||
| if self.ext in ['.psd']: | ||
| # silence warnings from psd-tools | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the warnings? Could this silence useful warnings as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings are custom thrown by the library. If there is an error, that still is caught. warnings look something like this: I remember doing some research into this when i originally did this PR, but Its been quite awhile and i can't remember much besides coming to the conclusion that it would be okay.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Warnings are fine since they are not exceptions. Your comment in the code also helps. We do want to catch exceptions thrown by |
||
| # Warnings warn of outdated depedency that is a pain to install | ||
| # and about colors being possibly wrong | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore") | ||
| image = PSDImage.load(self.source_file_path).as_PIL() | ||
| else: | ||
| image = Image.open(self.source_file_path) | ||
|
|
||
| if max_size: | ||
| # resize the image to the w/h maximum specified | ||
| ratio = min(max_size[0] / image.size[0], max_size[1] / image.size[1]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ pydocx==0.7.0 | |
|
|
||
| # Image | ||
| Pillow==2.8.2 | ||
| psd-tools==1.4 | ||
|
|
||
| # IPython | ||
| ipython==5.2.2 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For naming,
normalized_namemay be better thenextsince it is consistent (LINK). Or consider full wordextensionif no conflicting/shadowing issue. I understand it is confusing since thenormalized_nameis indeed the extension name (LINK).Our code base is not documented well. It will be great if we can gradually add doc string for functions and methods (e.g. for the ones that you modified, or the ones that you had a hard time to understand) that have many arguments. Here is an example where my description is not accurate and please revise:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext and self.ext was used as I saw it already being used elsewhere. Extension in MFR could refer to an actual extension library (eg the images extension, or Unoconv extension) So that is why it was avoided. normalized_name and ext are the same thing,
but the variable name doesnt make sense to me, so i did didn't use it.(dont remember why it is this way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Let's keep using
extthen and having the doc string should help for clarification.