Skip to content

Add loading image from filename. - #2778

Merged
daspecster merged 1 commit into
googleapis:masterfrom
daspecster:vision-add-filename-support
Dec 1, 2016
Merged

Add loading image from filename.#2778
daspecster merged 1 commit into
googleapis:masterfrom
daspecster:vision-add-filename-support

Conversation

@daspecster

Copy link
Copy Markdown
Contributor

Towards #2753

Adding support to pass in a filename when instantiating an Image.

@daspecsterdaspecster added the api: vision Issues related to the Cloud Vision API. label Nov 30, 2016
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 30, 2016
@daspecsterdaspecster mentioned this pull request Nov 30, 2016
10 tasks

@dhermesdhermes left a comment

Copy link
Copy Markdown
Contributor

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

Comment threaddocs/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.

Comment threaddocs/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.

Comment threaddocs/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.

This comment was marked as spam.

Comment threaddocs/vision-usage.rst Outdated

Image Properties
~~~~~~~~~~~~~~~~
----------------

This comment was marked as spam.

This comment was marked as spam.

Comment threadvision/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.

Comment threadvision/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.

"""

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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment threadvision/tox.ini
pip install --quiet --upgrade {toxinidir}/../core
deps =
{toxinidir}/../core
mock

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment threadvision/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.

Comment threadvision/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.

"""

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.

Comment threadvision/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.

Comment threadvision/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.

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.

This comment was marked as spam.

Comment threadvision/tox.ini
pip install --quiet --upgrade {toxinidir}/../core
deps =
{toxinidir}/../core
mock

This comment was marked as spam.

@daspecster

Copy link
Copy Markdown
ContributorAuthor

Thanks @dhermes! I cancelled travis and rerun after squashing.

@daspecster
daspecsterforce-pushed the vision-add-filename-support branch from b77ed78 to 0bc1c4bCompareDecember 1, 2016 20:00
@daspecster
daspecster merged commit e96c06a into googleapis:masterDec 1, 2016
@daspecster
daspecster deleted the vision-add-filename-support branch December 1, 2016 20:23
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
parthea pushed a commit that referenced this pull request Oct 21, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: visionIssues related to the Cloud Vision API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@daspecster@tseaver@dhermes@googlebot