-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add loading image from filename. #2778
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
Add loading image from filename. #2778
Conversation
dhermes
left a comment
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.
Mostly looks good (the benefit of tiny PRs!) though the constructor needs to be sorted out before I can sign off
docs/vision-usage.rst
Outdated
| >>> client = vision.Client(project='my-project', credentials=creds) | ||
| Creating an :class:`~google.cloud.vision.image.Image` object. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
docs/vision-usage.rst
Outdated
| Creating an :class:`~google.cloud.vision.image.Image` object. | ||
| ------------------------------------------------------------- | ||
|
|
||
| The :class:`~google.cloud.vision.image.Image` object is used to load your image |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
docs/vision-usage.rst
Outdated
| data from sources such as a Google Cloud Storage URI, raw bytes, or a file. | ||
|
|
||
|
|
||
| **From a Google Cloud Storage URI** |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
docs/vision-usage.rst
Outdated
| Image Properties | ||
| ~~~~~~~~~~~~~~~~ | ||
| ---------------- |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| self._source = source_uri | ||
| else: | ||
| self._content = _bytes_to_unicode(b64encode(_to_bytes(content))) | ||
| if filename: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| with open(filename, 'rb') as file_obj: | ||
| content = file_obj.read() | ||
|
|
||
| if content: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| """ | ||
|
|
||
| def __init__(self, client, content=None, source_uri=None): | ||
| def __init__(self, client, content=None, filename=None, source_uri=None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| pip install --quiet --upgrade {toxinidir}/../core | ||
| deps = | ||
| {toxinidir}/../core | ||
| mock |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/unit_tests/test_image.py
Outdated
| image = self._make_one(CLIENT_MOCK, content=IMAGE_CONTENT) | ||
|
|
||
| _AS_DICT = { | ||
| _as_dict = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/unit_tests/test_image.py
Outdated
| image = self._make_one(CLIENT_MOCK, source_uri=IMAGE_SOURCE) | ||
|
|
||
| _AS_DICT = { | ||
| _as_dict = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| """ | ||
|
|
||
| def __init__(self, client, content=None, source_uri=None): | ||
| def __init__(self, client, content=None, filename=None, source_uri=None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| def __init__(self, client, content=None, source_uri=None): | ||
| def __init__(self, client, content=None, filename=None, source_uri=None): | ||
| sources = set(source for source in (content, filename, source_uri) | ||
| if source is not None) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| if len(sources) != 1: | ||
| raise ValueError( | ||
| 'Specify exactly one of \'content\', \'filename\', or' | ||
| '\'source_uri\'.') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self._content = _bytes_to_unicode(b64encode(_to_bytes(content))) | ||
| if filename is not None: | ||
| with open(filename, 'rb') as file_obj: | ||
| content = file_obj.read() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| pip install --quiet --upgrade {toxinidir}/../core | ||
| deps = | ||
| {toxinidir}/../core | ||
| mock |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Thanks @dhermes! I cancelled travis and rerun after squashing. |
b77ed78 to
0bc1c4b
Compare
…e-support Add loading image from filename.
Add loading image from filename.
Towards #2753
Adding support to pass in a filename when instantiating an
Image.