profile_photo.utils package

Subpackages

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.

copy() a shallow copy of D[source]
get(key) _VT[source]

Do a case-insensitive lookup. This lower-cases key and looks up from the lower-cased key store.

get_key(key) str[source]

Return the original cased key

lower_items() Generator[tuple[str, _VT], None, None][source]

Like iteritems(), but with all lowercase keys.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

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/

profile_photo.utils.json_util module

profile_photo.utils.json_util.load_to_model(model_cls: type[W], data: W | dict | str | Path, param: Params | str) W[source]

Load data as an instance of a model class model_cls.

Module contents