<commit_before># -*- coding: utf-8 -*-
"""----------------------------------------------------------------------------
Author:
    <NAME> (wo1fSea)
    <EMAIL>
Date:
    2016/10/19
Description:
    ImageRect.py
----------------------------------------------------------------------------"""

from PIL import Image

from .Rect import Rect
from . import Utils

class ImageRect(Rect):
    """
    Image Rect data
    """

    def __init__(self, image_path=None):
        super(ImageRect, self).__init__(0, 0, 0, 0)

        self.image = None
        self.image_path = None
        self.source_size = (0, 0)
        self.source_box = (0, 0, 0, 0)

        self._rotated = False
        self._trimmed = False
        if image_path:
            self.load_image(image_path)
            self.image_path = image_path

    @property
    def rotated(self):
        return self._rotated

    @property
    def trimmed(self):
        return self._trimmed

    @property
    def bbox(self):
        if self._trimmed:
            return self.image.getbbox()
        else:
            return tuple(0, 0, self.width, self.height)

    def load_image(self, image_path):
        self.image = Image.open(image_path)
        self.image_path = image_path

        self.x, self.y = 0, 0
        self.width, self.height = self.image.size<commit_msg>mod: close the image object in load_image<commit_after># -*- coding: utf-8 -*-
"""----------------------------------------------------------------------------
Author:
    <NAME> (wo1fSea)
    <EMAIL>
Date:
    2016/10/19
Description:
    ImageRect.py
----------------------------------------------------------------------------"""

from PIL import Image

from .Rect import Rect
from . import Utils

class ImageRect(Rect):
    """
    Image Rect data
    """

    def __init__(self, image_path=None):
        super(ImageRect, self).__init__(0, 0, 0, 0)

        self.image = None
        self.image_path = None
        self.source_size = (0, 0)
        self.source_box = (0, 0, 0, 0)

        self._rotated = False
        self._trimmed = False
        if image_path:
            self.load_image(image_path)
            self.image_path = image_path

    @property
    def rotated(self):
        return self._rotated

    @property
    def trimmed(self):
        return self._trimmed

    @property
    def bbox(self):
        if self._trimmed:
            return self.image.getbbox()
        else:
            return tuple(0, 0, self.width, self.height)

    def load_image(self, image_path):
        image = Image.open(image_path)
        self.image = image.copy()
        image.close()

        self.image_path = image_path

        self.x, self.y = 0, 0
        self.width, self.height = self.image.size
{'fraction_non_alphanumeric': 0.21025641025641026, 'fraction_numerical': 0.017582417582417582, 'mean_word_length': 1.4427549194991056, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3073915', 'n_tokens_mistral': 837, 'n_tokens_neox': 783, 'n_words': 194}