Exemplo n.º 1
0
 def test_fontpointsize(self):
     img = Image((300, 200), 'red')
     img.font_pointsize(60)
     self.assertEqual(60, img.font_pointsize())
     self.assertEqual(float, type(img.font_pointsize()))
     img.annotate("hello", (100, 100))
     img.write('t.png')
Exemplo n.º 2
0
 def test_fontpointsize(self):
     img = Image((300, 200), 'red')
     img.font_pointsize(60)
     self.assertEqual(60, img.font_pointsize())
     self.assertEqual(float, type(img.font_pointsize()))
     img.annotate("hello", (100, 100))
     img.write('t.png')
Exemplo n.º 3
0
 def test_composite_arg_gravity(self):
     base = Image((300, 200), 'green')
     layer = Image((150, 100), 'transparent')
     drawer = Draw()
     drawer.circle(50, 50, 20, 20)
     layer.draw(drawer)
     base.composite(layer, 'center', 'over')
     base.write('t.png')
Exemplo n.º 4
0
 def test_composite_arg_gravity(self):
     base = Image((300, 200), 'green')
     layer = Image((150, 100), 'transparent')
     drawer = Draw()
     drawer.circle(50, 50, 20, 20)
     layer.draw(drawer)
     base.composite(layer, 'center', 'over')
     base.write('t.png')
Exemplo n.º 5
0
 def test_fontpointsize(self):
     img = Image((300, 200), 'red')
     img.font_pointsize(60)
     self.assertEqual(60, img.font_pointsize())
     self.assertEqual(float, type(img.font_pointsize()))
     if sys.platform.lower() == 'darwin':
         img.font("/Library/Fonts/Arial.ttf")
     img.annotate("hello", (100, 100))
     img.write('t.png')
Exemplo n.º 6
0
 def test_fontpointsize(self):
     img = Image((300, 200), 'red')
     img.font_pointsize(60)
     self.assertEqual(60, img.font_pointsize())
     self.assertEqual(float, type(img.font_pointsize()))
     if sys.platform.lower() == 'darwin':
         img.font("/Library/Fonts/Arial.ttf")
     img.annotate("hello", (100, 100))
     img.write('t.png')
Exemplo n.º 7
0
 def test_unicodefilename(self):
     self.img.write('unicode.png')
     if sys.version_info >= (3, ):
         img = Image('unicode.png')
     else:
         img = Image(unicode('unicode.png'))
     img.scale(0.5)
     if sys.version_info >= (3, ):
         img.write('unicode.jpg')
     else:
         img.write(unicode('unicode.jpg'))
Exemplo n.º 8
0
 def test_unicodefilename(self):
     self.img.write('unicode.png')
     if sys.version_info >= (3, ):
         img = Image('unicode.png')
     else:
         img = Image(unicode('unicode.png'))
     img.scale(0.5)
     if sys.version_info >= (3, ):
         img.write('unicode.jpg')
     else:
         img.write(unicode('unicode.jpg'))
Exemplo n.º 9
0
def image2norm(image_path, norm_path):
    print('image2norm(python) ' + image_path + ' ' + norm_path)
    sys.stdout.flush()

    ok = False
    try:
        img = Image(image_path)
        img.write(norm_path)
        ok = True
    except Exception as e:
        print(e)
        ok = False
    return ok
Exemplo n.º 10
0
def _ensure(id_, folderer, getter):
    folder = folderer(id_)
    # Create folder if it does not exists
    if not os.path.exists(folder):
        os.makedirs(folder)
    # Download image
    original = os.path.join(folder, ORIGINAL_FILENAME)
    if not os.path.exists(original):
        getter(original)
    # Create thumbnail
    thumb = os.path.join(folder, THUMBNAIL_FILENAME)
    if os.path.exists(original) and not os.path.exists(thumb):
        img = Image(original)
        img.scale((THUMBNAIL_SIZE, THUMBNAIL_SIZE))
        img.write(thumb)
Exemplo n.º 11
0
    def write(self, filename):
        try:
            return Image.write(self, filename)
        except Exception as e:
            if 'Warning' not in e.message:
                raise

            warnings.warn(e.message, RuntimeWarning)
Exemplo n.º 12
0
def read_ipfc(request, ip_sub_file_path):
    # only allow reading from session working directory (ip_sub_file_path must begin with uuid)
    file_path = os.path.join(config_path_work, ip_sub_file_path)
    if not os.path.exists(file_path):
        return HttpResponseNotFound("File not found %s vs %s" %
                                    (ip_sub_file_path, file_path))
    elif not os.path.isfile(file_path):
        return HttpResponseBadRequest("Not a file")
    else:
        file_size = fsize(file_path)
        if file_size <= config_max_filesize_viewer:
            mime = get_mime_type(file_path)
            print "MIME" + mime
            file_content = None
            if get_mime_type(file_path) == "image/png" or get_mime_type(
                    file_path) == "image/jpg":
                file_content = read_file_content(file_path)
                file_content = "data:" + mime + ";base64," + base64.b64encode(
                    file_content)
            elif get_mime_type(file_path) == "image/tiff" or get_mime_type(
                    file_path) == "image/gif":
                from pgmagick.api import Image
                img = Image(file_path)
                uuid = randomutils.getUniqueID()
                img.write('/tmp/%s.png' % uuid)
                print '/tmp/%s.png' % uuid
                file_content = "data:" + mime + ";base64," + base64.b64encode(
                    read_file_content('/tmp/%s.png' % uuid))
            elif get_mime_type(file_path) == "application/pdf":
                uuid = randomutils.getUniqueID()
                html_file = ('/tmp/%s.html' % uuid)
                pdftohtml_cmd = CliCommand.get("pdftohtml", {
                    'pdf_file': file_path,
                    'html_file': html_file
                })
                out = check_output(pdftohtml_cmd)
                file_content = read_file_content(html_file)
            else:
                file_content = read_file_content(file_path)
            return HttpResponse(file_content)
        else:
            return HttpResponseForbidden(
                "Size of requested file exceeds limit (file size %d > %d)" %
                (file_size, config_max_filesize_viewer))
Exemplo n.º 13
0
    def test_scale_with_filtertype(self):
        testset = {"Catrom": None, "Cubic": None, "None": None}
        for k, v in testset.items():
            img = Image((600, 400), 'gradient:#ffffff-#000000')
            if sys.platform.lower() == 'darwin':
                img.font("/Library/Fonts/Arial.ttf")
            img.annotate("hello", (100, 100))
            if k != "None":
                img.scale(0.6, k)
            else:
                img.scale(0.6)
            img.write('t.jpg')
            m = hashlib.md5()
            with open('t.jpg', 'rb') as fp:
                m.update(fp.read())
                testset[k] = m.hexdigest()

        self.assertNotEqual(testset["Catrom"], testset["None"])
        self.assertNotEqual(testset["Cubic"], testset["None"])
        self.assertNotEqual(testset["Catrom"], testset["Cubic"])
Exemplo n.º 14
0
    def pdf_to_images(self, ext="jpg"):
        ''' PDF to images '''
        assert os.path.isfile(self.data.path)
        i = 0
        medias = []
        while Image and True:
            try:
                image = Image("%s[%d]" % (self.data.path, i))
                image_file = os.path.join(
                    UPLOAD_TMP_DIR,
                    'pdf.%d.%d.%s' % (self.id, i, ext))
                image.write(image_file)
                media = MediaFile.create(
                    image_file, name=image_file.split('/')[-1:][0])
                medias.append(media)
            except Exception:
                #:TODO Exception type check
                break
            i = i + 1

        return medias
Exemplo n.º 15
0
 def test_scale_with_filtertype(self):
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6, 'Catrom')
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_with_filtertype_catrom_digest = m.hexdigest()
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6, 'Cubic')
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_with_filtertype_cubic_digest = m.hexdigest()
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6)
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_digest = m.hexdigest()
     self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
     self.assertNotEqual(scale_with_filtertype_catrom_digest,
                         scale_with_filtertype_cubic_digest)
Exemplo n.º 16
0
 def test_scale_with_filtertype(self):
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6, 'Catrom')
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_with_filtertype_catrom_digest = m.hexdigest()
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6, 'Cubic')
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_with_filtertype_cubic_digest = m.hexdigest()
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6)
     img.write('t.jpg')
     m = hashlib.md5()
     with open('t.jpg', 'rb') as fp:
         m.update(fp.read())
         scale_digest = m.hexdigest()
     self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
     self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)
Exemplo n.º 17
0
 def test_scale(self):
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6)
     img.write('t.jpg')
Exemplo n.º 18
0
 def test_unicodefilename(self):
     self.img.write('unicode.png')
     img = Image(u'unicode.png')
     img.scale(0.5)
     img.write(u'unicode.jpg')
Exemplo n.º 19
0
class ImageTestCase(unittest.TestCase):
    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Catrom')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_catrom_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Cubic')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_cubic_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_digest = m.hexdigest()
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
        self.assertNotEqual(scale_with_filtertype_catrom_digest,
                            scale_with_filtertype_cubic_digest)

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        if sys.platform.lower() == 'darwin':
            img.font("/Library/Fonts/Arial.ttf")
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        img = Image((500, 300), 'red')
        self.assertEqual(img.width, 500)
        self.assertEqual(img.height, 300)
        img.scale(0.5)
        self.assertEqual(img.width, 250)
        self.assertEqual(img.height, 150)
Exemplo n.º 20
0
class DrawTestCase(unittest.TestCase):
    def setUp(self):
        self.img = Image((600, 400), 'red')
        self.d = Draw()

    def test_affine(self):
        self.d.affine(10, 10, 20, 20, 40, 40)
        self.img.draw(self.d.drawer)
        self.img.write('t.jpg')

    def test_arc(self):
        self.d.arc(30, 30, 40, 40, 40, 40)
        self.img.draw(self.d.drawer)
        self.img.write('t.jpg')

    def test_bezier(self):
        points = ((30, 30), (50, 75), (200, 100))
        self.d.bezier(points)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_circle(self):
        self.d.circle(40, 40, 50, 100)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_color(self):
        self.d.color(40, 40, 'point')
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_composite(self):
        img1 = Image((20, 20), 'plasma:blue')
        self.d.composite(10, 10, 0, 0, img1)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_draw_for_draw_class(self):
        self.d.color(40, 40, 'point')
        self.d.circle(100, 100, 50, 100)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_ellipse(self):
        self.d.ellipse(150, 150, 120, 120, 0, 120)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_fill_color(self):
        self.d.fill_color('#f09060')
        self.d.ellipse(150, 150, 120, 120, 0, 120)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_fill_rule(self):
        self.d.fill_rule('evenodd')
        self.d.circle(150, 150, 50, 180)
        self.d.fill_rule('nonzero')
        self.d.circle(350, 150, 250, 180)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_fill_opacity(self):
        self.im = Image((600, 400), 'transparent')
        self.d.fill_color('red')
        self.d.fill_opacity(0.5)
        self.d.circle(150, 150, 50, 180)
        self.d.fill_color('green')
        self.d.fill_opacity(0.8)
        self.d.circle(160, 160, 50, 180)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_font_style_italic(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', 'italic')
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_font_style_oblique(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', 'oblique')
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_font_stretch_ultracondensed(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', 'oblique', stretch='ultracondensed')
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_font_stretch_extraexpanded(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', 'oblique', stretch='extraexpanded')
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_font_weight100(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', weight=100)
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_font_bold(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('vera.ttf', weight='bold')
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_gravity(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.gravity('center')
        self.d.text(0, 0, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_line(self):
        self.d.line(10, 10, 40, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_matte(self):
        self.d.matte(30, 30, 'filltoborder')
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_miterlimit(self):
        self.d.miterlimit(1)
        self.d.stroke_color('black')
        self.d.stroke_width(3)
        self.d.line(10, 200, 100, 10)
        self.d.line(100, 10, 210, 200)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.miterlimit(18)
        self.d.stroke_color('black')
        self.d.stroke_width(3)
        self.d.stroke_opacity(0.5)
        self.d.fill_opacity(0.5)
        self.d.line(210, 200, 300, 10)
        self.d.line(300, 10, 410, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_path(self):
        paths = ((40, 30), )
        self.d.path(paths)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_point(self):
        for i in range(50):
            self.d.point(i, i + 10)
        for i in range(50, 200, 2):
            self.d.point(i, i + 10)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_pointsize(self):
        self.d.pointsize(10)
        self.d.pointsize(30.)
        self.d.circle(150, 150, 50, 180)
        self.img.draw(self.d.drawer)
        self.img.write('t.png')

    def test_polygon(self):
        coordinate = ((10, 10), (20, 30), (40, 50))
        self.d.polygon(coordinate)
        coordinate = [(100, 100), (150, 100), [150, 150], (100, 150)]
        self.d.polygon(coordinate)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_polyline(self):
        coordinate = ((10, 10), (20, 30), (40, 50))
        self.d.polyline(coordinate)
        coordinate = [(100, 100), (150, 100), [150, 150], (100, 150)]
        self.d.polyline(coordinate)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_rectangle(self):
        self.d.rectangle(50, 50, 100, 100)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_rotation(self):
        self.d.rectangle(150, 150, 200, 200)
        self.d.rotation(40)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.8)
        self.d.rectangle(150, 150, 200, 200)
        self.d.rotation(20)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.rectangle(150, 150, 200, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_round_rectangle(self):
        self.d = Draw()
        self.d.round_rectangle(20, 20, 30, 30, 150, 150)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_scaling(self):
        self.d.scaling(0.4, 0.4)
        self.d.circle(150, 150, 150, 200)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(150, 150, 150, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_skew(self):
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.d.skewx(40)
        self.img.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.d.skewy(40)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_stroke_antialias(self):
        self.d.stroke_color('black')
        self.d.stroke_width(20)
        self.d.stroke_antialias(True)
        self.d.line(10, 10, 40, 200)
        self.d.stroke_antialias(False)
        self.d.line(50, 10, 80, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_stroke_linecap(self):
        self.d.stroke_color('lime')
        self.d.stroke_linecap('butt')
        self.d.stroke_linecap('round')
        self.d.stroke_linecap('square')
        self.d.line(10, 10, 40, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    @unittest.skipIf(LIBGM_VERSION <= [1, 3, 18],
                     "bug in gm version: %s" % str(LIBGM_VERSION))
    def test_stroke_linejoin(self):
        self.d.stroke_color('lime')
        self.d.stroke_linejoin('round')
        self.d.stroke_linejoin('bevel')
        self.d.stroke_linejoin('miter')
        self.d.line(10, 10, 40, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_stroke_color(self):
        self.d.stroke_color('lime')
        self.d.line(10, 10, 40, 200)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_stroke_width(self):
        self.d.stroke_width(20)
        self.d.line(20, 20, 50, 210)
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_text(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.text(30, 30, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_text_antialias(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.font('courier', weight='bold')
        self.d.pointsize(70)
        self.d.text_antialias(False)
        self.d.text(30, 100, "hello pgmagick")
        self.d.text_antialias(True)
        self.d.text(30, 200, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_text_decoration(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.pointsize(70)
        self.d.text_decoration('overline')
        self.d.text(30, 100, "hello pgmagick")
        self.d.text_decoration('linethrough')
        self.d.text(30, 200, "hello pgmagick")
        self.d.text_decoration('underline')
        self.d.text(30, 300, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_text_undercolor(self):
        if sys.platform.lower() == 'darwin':
            self.skipTest("DrawableFont() is broken")
        self.d.pointsize(70)
        self.d.text_undercolor('lime')
        self.d.text(30, 100, "hello pgmagick")
        self.img.draw(self.d)
        self.img.write('t.png')

    def test_translate(self):
        self.d.translate(10, 200)
        self.img.draw(self.d)
        self.img.write('t.png')
Exemplo n.º 21
0
# coding: utf-8
from pgmagick.api import Image

img = Image((300, 200))
img.font("/etc/alternatives/fonts-japanese-gothic.ttf")
img.annotate('Hello World')
img.annotate('ようこそpgmagickへ!!')
img.write('japanese-text.png')
Exemplo n.º 22
0
class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        if sys.version_info >= (3, ):
            img = Image('unicode.png')
        else:
            img = Image(unicode('unicode.png'))
        img.scale(0.5)
        if sys.version_info >= (3, ):
            img.write('unicode.jpg')
        else:
            img.write(unicode('unicode.jpg'))

    def test_nonarg(self):
        im = Image()

    def test_arg(self):
        im = Image((600, 400), 'red')

    def test_arg_float(self):
        im = Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        im = Image((600, 400), 'red')
        im.scale(0.6)
        im.write('t.jpg')

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        im = Image((500, 300), 'red')
        self.assertEqual(im.width, 500)
        self.assertEqual(im.height, 300)
        im.scale(0.5)
        self.assertEqual(im.width, 250)
        self.assertEqual(im.height, 150)
Exemplo n.º 23
0
 def test_scale(self):
     img = Image((600, 400), 'gradient:#ffffff-#000000')
     img.scale(0.6)
     img.write('t.jpg')
Exemplo n.º 24
0
 def test_unicodefilename(self):
     self.img.write('unicode.png')
     img = Image(u'unicode.png')
     img.scale(0.5)
     img.write(u'unicode.jpg')
Exemplo n.º 25
0
 def test_crop(self):
     img = Image((300, 200), 'gradient:#ffff00-#00ffff')
     img.crop(20, 20, 50, 100)
     img.write('t.png')
Exemplo n.º 26
0
class ImageTestCase(unittest.TestCase):
    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        if sys.version_info >= (3, ):
            img = Image('unicode.png')
        else:
            img = Image(unicode('unicode.png'))
        img.scale(0.5)
        if sys.version_info >= (3, ):
            img.write('unicode.jpg')
        else:
            img.write(unicode('unicode.jpg'))

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        im = Image((600, 400), 'red')
        im.scale(0.6)
        im.write('t.jpg')

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        im = Image((500, 300), 'red')
        self.assertEqual(im.width, 500)
        self.assertEqual(im.height, 300)
        im.scale(0.5)
        self.assertEqual(im.width, 250)
        self.assertEqual(im.height, 150)
Exemplo n.º 27
0
class DrawTestCase(unittest.TestCase):

    def setUp(self):
        self.im = Image((600, 400), 'red')
        self.d = Draw()

    def test_affine(self):
        self.d.affine(10, 10, 20, 20, 40, 40)
        self.im.draw(self.d.drawer)
        self.im.write('t.jpg')

    def test_arc(self):
        self.d.arc(30, 30, 40, 40, 40, 40)
        self.im.draw(self.d.drawer)
        self.im.write('t.jpg')

    def test_bezier(self):
        points = ((30, 30), (50, 75), (200, 100))
        self.d.bezier(points)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_circle(self):
        self.d.circle(40, 40, 50, 100)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_color(self):
        self.d.color(40, 40, 'point')
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_composite(self):
        img1 = Image((20, 20), 'plasma:blue')
        self.d.composite(10, 10, 0, 0, img1)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_draw_for_draw_class(self):
        self.d.color(40, 40, 'point')
        self.d.circle(100, 100, 50, 100)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_ellipse(self):
        self.d.ellipse(150, 150, 120, 120, 0, 120)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_fill_color(self):
        self.d.fill_color('#f09060')
        self.d.ellipse(150, 150, 120, 120, 0, 120)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_fill_rule(self):
        self.d.fill_rule('evenodd')
        self.d.circle(150, 150, 50, 180)
        self.d.fill_rule('nonzero')
        self.d.circle(350, 150, 250, 180)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_fill_opacity(self):
        self.im = Image((600, 400), 'transparent')
        self.d.fill_color('red')
        self.d.fill_opacity(0.5)
        self.d.circle(150, 150, 50, 180)
        self.d.fill_color('green')
        self.d.fill_opacity(0.8)
        self.d.circle(160, 160, 50, 180)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_font_style_italic(self):
        self.d.font('vera.ttf', 'italic')
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_font_style_oblique(self):
        self.d.font('vera.ttf', 'oblique')
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_font_stretch_ultracondensed(self):
        self.d.font('vera.ttf', 'oblique', stretch='ultracondensed')
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_font_stretch_extraexpanded(self):
        self.d.font('vera.ttf', 'oblique', stretch='extraexpanded')
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_font_weight100(self):
        self.d.font('vera.ttf', weight=100)
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_font_bold(self):
        self.d.font('vera.ttf', weight='bold')
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_gravity(self):
        self.d.gravity('center')
        self.d.text(0, 0, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_line(self):
        self.d.line(10, 10, 40, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_matte(self):
        self.d.matte(30, 30, 'filltoborder')
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_miterlimit(self):
        self.d.miterlimit(0)
        self.d.stroke_color('black')
        self.d.stroke_width(3)
        self.d.line(10, 200, 100, 10)
        self.d.line(100, 10, 210, 200)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.miterlimit(18)
        self.d.stroke_color('black')
        self.d.stroke_width(3)
        self.d.stroke_opacity(0.5)
        self.d.fill_opacity(0.5)
        self.d.line(210, 200, 300, 10)
        self.d.line(300, 10, 410, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_path(self):
        paths = ((40, 30),)
        self.d.path(paths)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_point(self):
        for i in range(50):
            self.d.point(i, i + 10)
        for i in range(50, 200, 2):
            self.d.point(i, i + 10)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_pointsize(self):
        self.d.pointsize(10)
        self.d.pointsize(30.)
        self.d.circle(150, 150, 50, 180)
        self.im.draw(self.d.drawer)
        self.im.write('t.png')

    def test_polygon(self):
        coordinate = ((10, 10), (20, 30), (40, 50))
        self.d.polygon(coordinate)
        coordinate = [(100, 100), (150, 100), [150, 150], (100, 150)]
        self.d.polygon(coordinate)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_polyline(self):
        coordinate = ((10, 10), (20, 30), (40, 50))
        self.d.polyline(coordinate)
        coordinate = [(100, 100), (150, 100), [150, 150], (100, 150)]
        self.d.polyline(coordinate)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_rectangle(self):
        self.d.rectangle(50, 50, 100, 100)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_rotation(self):
        self.d.rectangle(150, 150, 200, 200)
        self.d.rotation(40)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.8)
        self.d.rectangle(150, 150, 200, 200)
        self.d.rotation(20)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.rectangle(150, 150, 200, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_round_rectangle(self):
        self.d.round_rectangle(200, 200, 30, 30, 15, 15)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_scaling(self):
        self.d.scaling(0.4, 0.4)
        self.d.circle(150, 150, 150, 200)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(150, 150, 150, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_skew(self):
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.d.skewx(40)
        self.im.draw(self.d)
        self.d = Draw()
        self.d.fill_opacity(0.6)
        self.d.circle(50, 50, 50, 100)
        self.d.skewy(40)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_stroke_antialias(self):
        self.d.stroke_color('black')
        self.d.stroke_width(20)
        self.d.stroke_antialias(True)
        self.d.line(10, 10, 40, 200)
        self.d.stroke_antialias(False)
        self.d.line(50, 10, 80, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_stroke_linecap(self):
        self.d.stroke_color('lime')
        self.d.stroke_linecap('butt')
        self.d.stroke_linecap('round')
        self.d.stroke_linecap('square')
        self.d.line(10, 10, 40, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_stroke_linejoin(self):
        self.d.stroke_color('lime')
        self.d.stroke_linejoin('round')
        self.d.stroke_linejoin('bevel')     # FIXME: Unit Test Error
        self.d.stroke_linejoin('miter')
        self.d.line(10, 10, 40, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_stroke_color(self):
        self.d.stroke_color('lime')
        self.d.line(10, 10, 40, 200)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_stroke_width(self):
        self.d.stroke_width(20)
        self.d.line(20, 20, 50, 210)
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_text(self):
        self.d.text(30, 30, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_text_antialias(self):
        self.d.font('courier', weight='bold')
        self.d.pointsize(70)
        self.d.text_antialias(False)
        self.d.text(30, 100, "hello pgmagick")
        self.d.text_antialias(True)
        self.d.text(30, 200, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_text_decoration(self):
        self.d.pointsize(70)
        self.d.text_decoration('overline')
        self.d.text(30, 100, "hello pgmagick")
        self.d.text_decoration('linethrough')
        self.d.text(30, 200, "hello pgmagick")
        self.d.text_decoration('underline')
        self.d.text(30, 300, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_text_undercolor(self):
        self.d.pointsize(70)
        self.d.text_undercolor('lime')
        self.d.text(30, 100, "hello pgmagick")
        self.im.draw(self.d)
        self.im.write('t.png')

    def test_translate(self):
        self.d.translate(10, 200)
        self.im.draw(self.d)
        self.im.write('t.png')
Exemplo n.º 28
0
 def test_crop(self):
     img = Image((300, 200), 'gradient:#ffff00-#00ffff')
     img.crop(20, 20, 50, 100)
     img.write('t.png')
Exemplo n.º 29
0
 def test_scale(self):
     im = Image((600, 400), 'red')
     im.scale(0.6)
     im.write('t.jpg')
Exemplo n.º 30
0
 def test_scale(self):
     im = Image((600, 400), 'red')
     im.scale(0.6)
     im.write('t.jpg')
Exemplo n.º 31
0
class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Catrom')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_catrom_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Cubic')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_cubic_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_digest = m.hexdigest()
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
        img = Image((300, 200), 'gradient:#ffff00-#00ffff')
        img.crop(20, 20, 50, 100)
        img.write('t.png')

    def test_fontpointsize(self):
        img = Image((300, 200), 'red')
        img.font_pointsize(60)
        self.assertEqual(60, img.font_pointsize())
        self.assertEqual(float, type(img.font_pointsize()))
        if sys.platform.lower() == 'darwin':
            img.font("/Library/Fonts/Arial.ttf")
        img.annotate("hello", (100, 100))
        img.write('t.png')

    def test_size_property(self):
        img = Image((500, 300), 'red')
        self.assertEqual(img.width, 500)
        self.assertEqual(img.height, 300)
        img.scale(0.5)
        self.assertEqual(img.width, 250)
        self.assertEqual(img.height, 150)