profile_photo.utils package¶
Subpackages¶
- profile_photo.utils.aws package
- Submodules
- profile_photo.utils.aws.client_cache module
- profile_photo.utils.aws.rekognition module
- profile_photo.utils.aws.rekognition_models module
BoundingBoxCompareFacesRespCoordinatesDetectFacesRespDetectLabelsRespFaceFaceDetailFaceDetail.age_rangeFaceDetail.beardFaceDetail.bounding_boxFaceDetail.confidenceFaceDetail.emotion_to_confidenceFaceDetail.emotionsFaceDetail.eyeglassesFaceDetail.eyes_openFaceDetail.genderFaceDetail.landmarksFaceDetail.mouth_openFaceDetail.mustacheFaceDetail.poseFaceDetail.qualityFaceDetail.smileFaceDetail.sunglasses
LabelLandmarkRecognizeCelebritiesResp
- profile_photo.utils.aws.rekognition_utils module
- profile_photo.utils.aws.s3 module
- Module contents
Submodules¶
profile_photo.utils.create_headshot module¶
- profile_photo.utils.create_headshot.rotate_im_and_crop(fp: str, faces: DetectFacesResp, labels: DetectLabelsResp | None, file_ext: str | None = None, im_bytes: bytes = None, debug: bool = False) ProfilePhoto[source]¶
profile_photo.utils.dict_helper module¶
Dict helper module
- class profile_photo.utils.dict_helper.DictWithLowerStore(data=None, **kwargs)[source]¶
Bases:
Dict[_KT,_VT]A
dict-like object with a lower-cased key store.All keys are expected to be strings. The structure remembers the case of the lower-cased key to be set, and methods like
get()and``get_key()`` will use the lower-cased store. However, querying and contains testing is case sensitive:dls = DictWithLowerStore() dls['Accept'] = 'application/json' dls['aCCEPT'] == 'application/json' # False dls.get('aCCEPT') == 'application/json' # True list(dls) == ['Accept'] # True
Note: I don’t want to use the CaseInsensitiveDict from request.structures`, because it turns out the lookup via that dict implementation is rather slow. So this version is somewhat of a trade-off, where I retain the same speed on lookups as a plain dict, but I also have a lower-cased key store, in case I ever need to use it.
- get(key) _VT[source]¶
Do a case-insensitive lookup. This lower-cases key and looks up from the lower-cased key store.
profile_photo.utils.img_orient module¶
Rotate an image based on its EXIF orientation flag. All EXIF metadata will be removed from the transposed image.
Ref: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- profile_photo.utils.img_orient.get_im_orientation(im_bytes: bytes, orientation: int | None | MISSING = <dataclasses._MISSING_TYPE object>) -> (PILImage | None, bool, int | None)[source]¶
Check if the image has been rotated, and get the image’s orientation.
- Example:
>>> with open('file.jpg', 'rb') as in_file: >>> im_bytes = in_file.read() >>> pil_im, is_rotated, orientation = get_im_orientation(im_bytes)
Return a three-element tuple of (pil_image, is_rotated, orientation_flag)
- profile_photo.utils.img_orient.get_oriented_im_bytes(file_ext: str, im_bytes: bytes = None, orientation: int | None | MISSING = <dataclasses._MISSING_TYPE object>) -> (bytes, bool)[source]¶
Performs the same operation as PIL.ImageOps.exif_transpose, but using the OpenCV library.
Returns a two-element tuple of (rotated_im_bytes, rotated). If an image has an EXIF Orientation tag, return a new image (as bytes) that is transposed accordingly. Otherwise, the rotated value will be false.
- profile_photo.utils.img_orient.resize_ims_and_concat_h(im1: Image, im2: Image, resample=3, resize_big_image=True) Image[source]¶
Resize two PIL Images and tile them horizontally.
Source: https://note.nkmk.me/en/python-pillow-concat-images/