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_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_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_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)
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_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_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 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
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))
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"])
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 print_all_property(): origin_img = Image('test.jpg') print "%dx%d" % (origin_img.width, origin_img.height)
def test_scale(self): img = Image((600, 400), 'gradient:#ffffff-#000000') img.scale(0.6) img.write('t.jpg')
def test_arg_float(self): Image((600.5, 400.4), 'red')
def test_arg(self): Image((600, 400), 'red')
def test_nonarg(self): Image()
def setUp(self): self.im = Image((600, 400), 'red') self.d = Draw()
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_scale(self): im = Image((600, 400), 'red') im.scale(0.6) im.write('t.jpg')
# 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')
def test_crop(self): img = Image((300, 200), 'gradient:#ffff00-#00ffff') img.crop(20, 20, 50, 100) img.write('t.png')
def setUp(self): self.img = Image((600, 400), 'red')
def test_nonarg(self): im = Image()