-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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 GCF imagemagick samples #1684
Conversation
Change-Id: Ie8aca88b0dc80926438c9e87b2e71071f8f294d6
Change-Id: I75ec970fd22c870664e4133f51562793a464df1f
Change-Id: I255301ab7218b591c6c61f7da059a3d577bd3186
functions/imagemagick/main.py
Outdated
def blur_offensive_images(data, context): | ||
file = data | ||
|
||
# Exit if this is a deletion or a deploy event. |
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.
Are these the best canonical ways of determine what kind of event it is? It seems a little haphazard to check for a name or state in this way as the only method.
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.
Given that we can configure triggers to fire only on certain events (e.g. file writes), probably not.
We can delete this code from the Node sample as well - but we'll want to explicitly specify which event to use in the docs.
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.
What do you want to do in this situation then, leave it or change it somehow? We should be careful to follow the most straightforward, best-documented practice we can in either this or the Node case.
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.
Oh, I see it's been changed in the latest revision. Never mind. Thanks!
functions/imagemagick/main.py
Outdated
print('Image %s was downloaded to %s.' % (file_name, temp_local_filename)) | ||
|
||
# Blur the image using ImageMagick. | ||
subprocess.check_call([ |
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.
Is there any in-Python way to do this, for instance by using Pillow or an ImageMagick binding for Python, that doesn't involve a subprocess call?
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.
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.
Great, wand
is a good solution here.
Change-Id: I31808597e16b7b2201adbd8a51fe84241c90e649
Change-Id: I465cb4531a024265f66f857cbd793949b597d252
Change-Id: Ie69ce88686481640da59207682b078b800631620
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.
lgtm if remaining discussions are closed to your satisfaction.
functions/imagemagick/main.py
Outdated
# Blurs the given file using ImageMagick. | ||
def __blur_image(blob): | ||
file_name = blob.name | ||
temp_local_filename = '/tmp/%s' % os.path.basename(file_name) |
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.
Rather than hardcoding /tmp, can we use tempfile.mkdtemp
to get a random, guaranteed-temporary directory? (note, we should clean this up afterwards as well)
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.
(One reason is to avoid filename conflicts or race conditions.)
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.
Done (with mkstemp
instead.)
functions/imagemagick/main.py
Outdated
def blur_offensive_images(data, context): | ||
file = data | ||
|
||
# Exit if this is a deletion or a deploy event. |
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.
What do you want to do in this situation then, leave it or change it somehow? We should be careful to follow the most straightforward, best-documented practice we can in either this or the Node case.
functions/imagemagick/main.py
Outdated
print('Image %s was downloaded to %s.' % (file_name, temp_local_filename)) | ||
|
||
# Blur the image using ImageMagick. | ||
subprocess.check_call([ |
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.
Great, wand
is a good solution here.
Change-Id: I62036d693fcf2451fbd1129d6799a736852ea455
Best-practices question: this function triggers twice - once when the original file is uploaded, and a second time when the file is blurred. (The Node sample also does this.) Should we address this in the sample and/or docs? |
Could we design it not to do that somehow?
…On Fri, Sep 14, 2018 at 4:18 PM Ace Nassri ***@***.***> wrote:
Best-practices question: this function triggers *twice* - once when the
original file is uploaded, and a second time when the file is blurred. (The
Node sample also does this.)
Should we address this in the sample and/or docs?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1684 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAp51wYdUo4YAlyGfsvFWwfCrA9f0d6eks5ubDlFgaJpZM4WaMgw>
.
|
Probably the best workaround is to upload to a different bucket altogether...which has its own costs. Maybe we should just call it out in the docs? (I'll ping @labtopia about/continue this thread internally.) |
That's also the workaround I was thinking of. An alternative would be to
prefix the names of blur uploads with a constant like "blurred-" and have
the function look for that prefix and abort, with a comment explaining the
issue.
I would prefer some workaround or another be implemented because it seems
like not fixing this would open the function up to an infinite loop if the
content identifier malfunctions upstream, and that customers modifying this
function to meet their needs could easily also run into a similar problem.
The workaround can be commented to alert customers to the potential issue
as well.
…On Fri, Sep 14, 2018, 4:23 PM Ace Nassri ***@***.***> wrote:
Probably the best workaround is to upload to a different bucket
altogether...which has its own costs.
Maybe we should just call it out in the docs?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1684 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAp511OEeHGy-2N8U_MvVGOGPIzd3KHDks5ubDpkgaJpZM4WaMgw>
.
|
In the documented use case, it seems like it wouldn't be an issue. (Eventually, the blurring will obscure the image so much that the Vision API doesn't detect anything.) I agree we should document how to handle user-provided cases though. Would including a comment on this in the sample be enough? |
I would personally prefer if we actually architected the sample to make
certain it only runs once. This will make it clearer to the user how to do
it than any comment, and also I'm iffy about relying on the vision
detection algorithm to work and prevent an infininte loop 100% of the time.
Andrew
…On Mon, Sep 17, 2018 at 2:33 PM Ace Nassri ***@***.***> wrote:
In the *documented* use case, it seems like it wouldn't be an issue.
(Eventually, the blurring will obscure the image so much that the Vision
API doesn't detect anything.)
I agree we should document how to handle *user-provided* cases though.
Would commenting on this in the sample be enough?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1684 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAp5107_2ZGDM2MZXjOrA-5llZ2-rsY4ks5ucBUtgaJpZM4WaMgw>
.
|
Change-Id: Iaddf913fd9be99e7daff6caf45aac2a03c1dceeb
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.
LGTM :)
TODO - add Kokoro test config. (@andrewsg this is good to review though.)EDIT: Kokoro configs need to be added for GCF separately. We should do this in a separate PR.