コード例 #1
0
ファイル: utils.py プロジェクト: ts-mk/phatch
def analyze(original, other):
    """Analyze the difference between the two images"""
    result = {}
    from lib import openImage
    original_image = openImage.open(original)
    other_image = openImage.open(other)
    if other_image.mode != original_image.mode:
        result['reason'] = 'Mismatching modes %s != %s' % (
            other_image.mode,
            original_image.mode)
    elif other_image.size != original_image.size:
        result['reason'] = 'Mismatching sizes %s != %s' % (
            other_image.size,
            original_image.size)
    elif original_image.info != other_image.info:
        diff = info_diff(original_image.info, other_image.info)
        result['reason'] = 'Mismatching info\n\t%s' % diff
    elif not match_metadata(original, other):
        result['reason'] = 'Mismatching metadata'
    else:
        diff_image = image_diff(original_image, other_image)
        if diff_image:
            result['reason'] = 'Mismatching pixels'
            result['diff'] = diff_image
        else:
            result['reason'] = 'Unidentifiable difference'
    return result
コード例 #2
0
ファイル: tamogen.py プロジェクト: CamelliaDPG/Camellia
def mosaic(im, filltype, x_squares, y_squares, x_pix, y_pix, fill_image=None, fill_folder=None):
    assert filltype in FILL_TYPES

    fill_size = (x_pix, y_pix)
    num_squares = (min(x_squares, x_pix), min(y_squares, y_pix))
    final_img = Image.new(im.mode, fill_size)

    fill_section_size = get_section_size(fill_size, num_squares)
    im_section_size = get_section_size(im.size, num_squares)

    # calculate missing pixels for dispersion algo to avoid blank pixels
    missing_column_pixels = fill_size[0] - num_squares[0] * fill_section_size[0]
    missing_row_pixels = fill_size[1] - num_squares[1] * fill_section_size[1]

    # alter section sizes based on missing pixels
    if missing_row_pixels:
        fill_section_size[0] += 1
        im_section_size[0] += 1

    if missing_column_pixels:
        fill_section_size[1] += 1
        im_section_size[1] += 1

    boxes = BoundingBoxContainer()
    boxes.append("fill_box", (0, 0), fill_section_size)
    boxes.append("im_box", (0, 0), im_section_size)

    fill_images = FillImages(fill_section_size, im.mode)

    if filltype == IMAGE_ITSELF:
        fill_images.append(im)
    elif filltype == OTHER_IMAGE:
        fill_images.append(openImage.open(fill_image))
    elif filltype == FOLDER:
        for file_name in glob.iglob(os.path.join(fill_folder, "*")):
            try:
                fill_images.append(openImage.open(file_name))
            except IOError:
                pass

    for column in range(num_squares[0]):
        for row in range(num_squares[1]):
            bsection = im.crop(boxes["im_box"])
            fill_img, tone_diff = fill_images.findClosestImageAndToneDiff(bsection)
            set_new_tone(fill_img.copy(), tone_diff, boxes["fill_box"], final_img)
            boxes.move_down()

        boxes.reset_y()
        boxes.move_right()

    return final_img
コード例 #3
0
def mosaic(im, filltype, x_squares, y_squares, x_pix, y_pix, fill_image=None, fill_folder=None):
    assert filltype in FILL_TYPES

    fill_size = (x_pix, y_pix)
    num_squares = (min(x_squares, x_pix), min(y_squares, y_pix))
    final_img = Image.new(im.mode, fill_size)

    fill_section_size = get_section_size(fill_size, num_squares)
    im_section_size = get_section_size(im.size, num_squares)

    # calculate missing pixels for dispersion algo to avoid blank pixels
    missing_column_pixels = fill_size[0] - num_squares[0] * fill_section_size[0]
    missing_row_pixels = fill_size[1] - num_squares[1] * fill_section_size[1]

    # alter section sizes based on missing pixels
    if missing_row_pixels:
        fill_section_size[0] += 1
        im_section_size[0] += 1

    if missing_column_pixels:
        fill_section_size[1] += 1
        im_section_size[1] += 1

    boxes = BoundingBoxContainer()
    boxes.append('fill_box', (0, 0), fill_section_size)
    boxes.append('im_box', (0, 0), im_section_size)

    fill_images = FillImages(fill_section_size, im.mode)

    if filltype == IMAGE_ITSELF:
        fill_images.append(im)
    elif filltype == OTHER_IMAGE:
        fill_images.append(openImage.open(fill_image))
    elif filltype == FOLDER:
        for file_name in glob.iglob(os.path.join(fill_folder, '*')):
            try:
                fill_images.append(openImage.open(file_name))
            except IOError:
                pass

    for column in range(num_squares[0]):
        for row in range(num_squares[1]):
            bsection = im.crop(boxes['im_box'])
            fill_img, tone_diff = fill_images.findClosestImageAndToneDiff(bsection)
            set_new_tone(fill_img.copy(), tone_diff, boxes['fill_box'], final_img)
            boxes.move_down()

        boxes.reset_y()
        boxes.move_right()

    return final_img
コード例 #4
0
ファイル: preview.py プロジェクト: yorik-freecad-blog/phatch
def generate(source, size=(48, 48), path=USER_PREVIEW_PATH, force=True):
    source_image = openImage.open(source)
    source_image.thumbnail((min(source_image.size[0], size[0] * 1),
                            min(source_image.size[0], size[0] * 1)),
                           Image.ANTIALIAS)
    ensure_path(path)
    for Action in api.ACTIONS.values():
        action = Action()
        filename = os.path.join(path, action.label + '.png')
        if os.path.exists(filename) and not force:
            continue
        action.init()
        result = action.apply_pil(source_image.copy())
        result.thumbnail(size, Image.ANTIALIAS)
        result.save(filename)
コード例 #5
0
ファイル: preview.py プロジェクト: Pierantonio/phatch
def generate(source, size=(48, 48), path=USER_PREVIEW_PATH, force=True):
    source_image = openImage.open(source)
    source_image.thumbnail(
        (min(source_image.size[0], size[0] * 1),
        min(source_image.size[0], size[0] * 1)),
        Image.ANTIALIAS)
    ensure_path(path)
    for Action in api.ACTIONS.values():
        action = Action()
        filename = os.path.join(path, action.label + '.png')
        if os.path.exists(filename) and not force:
            continue
        action.init()
        result = action.apply_pil(source_image.copy())
        result.thumbnail(size, Image.ANTIALIAS)
        result.save(filename)
コード例 #6
0
ファイル: pil.py プロジェクト: sean-abbott/phatch
 def open(self, uri):
     self.image = openImage.open(uri)
     if self.image.mode in ['F', 'I']:
         # Phatch doesn't support F and I
         # FIXME: It will better to add some sort of warning here
         self.image = self.image.convert('L')
コード例 #7
0
 def open(self, uri):
     self.image = openImage.open(uri)
     if self.image.mode in ['F', 'I']:
         # Phatch doesn't support F and I
         # FIXME: It will better to add some sort of warning here
         self.image = self.image.convert('L')