File: utils.py

package info (click to toggle)
pilkit 3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: python: 958; makefile: 130; sh: 6
file content (31 lines) | stat: -rw-r--r-- 644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from pilkit.lib import Image


def get_image_file(image_name='reference.png'):
    """
    See also:

    http://en.wikipedia.org/wiki/Lenna
    http://sipi.usc.edu/database/database.php?volume=misc&image=12

    """
    dir = os.path.dirname(__file__)
    path = os.path.join(dir, 'assets', image_name)
    return open(path, 'r+b')

def create_image():
    return Image.open(get_image_file())

def compare_images(a, b):
  if a.size != b.size:
    return False

  rows, cols = a.size

  for row in range(rows):
    for col in range(cols):
      if a.getpixel((row, col)) != b.getpixel((row, col)):
        return False

  return True