-
Notifications
You must be signed in to change notification settings - Fork 321
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
[py-tx] Create rotation helper functions in PhotoContent using Pillow #1671
Conversation
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.
Looking good!
To test this, on your development environment, create a simple image, and then call, via Ipython the method and write the resultant bytes to files.
You may find that for some image types, you need to hint pillow on what the format is, which can be done via filename.
You can write the bytes to files and then visually inspect that you have all the rotations! You can include that code in your test plan.
python-threatexchange/threatexchange/content_type/content_base.py
Outdated
Show resolved
Hide resolved
@classmethod | ||
def rotate_image(cls, image_data: bytes, angle: float) -> bytes: | ||
""" | ||
Rotate an image by a given angle |
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.
Include a note on why we might want to do this :P
Namely, this is help for testing hash algorithms.
return buffer.getvalue() | ||
|
||
@classmethod | ||
def try_all_rotations(cls, image_data: bytes): |
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.
nit: Let's go with all_simple_rotations
@classmethod | ||
def try_all_rotations(cls, image_data: bytes): | ||
""" | ||
Try all possible rotations to the image |
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.
nit: Something like
"""
Generate the 8 naive rotations of an image.
This can be helpful for testing, and for image algorithms that don't have
a native way to generate rotations during hashing, this can be a way to
brute force rotations.
@Dcallies Thank you for your comments! I have included the docstring where necessary and also tested it on my development environment. If the code is ok, I can start moving to next step which is adding a new command line option (--rotations) |
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.
So close!
Can you:
- Run
black
so CI passes - Confirm that you did something like the test plan?
Yes I have done the test plan and update the PR's description |
@Dcallies it seems like StrEnum cannot be imported with py version before 3.11 |
Oh no! I totally missed that. For now, use |
@Dcallies Fixed! Lmk if you have any other 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.
Nice job!
@@ -7,6 +7,7 @@ | |||
This records all the valid signal types for a piece of content. | |||
""" | |||
|
|||
from enum import Enum, auto |
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.
nit: auto unused
Summary
This is a part of the issue #1665
This has been discussed previously in PR #1669
Test plan
@Dcallies said not to write a unittest at this stage.
However, I was able to show that the code is correct by writing a simple bit of python:
Then I visually inspected all the files to confirm they were rotated as expected.