说明
python placeholderimage示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。
编程语言: Python
命名空间/包名称: placeholder
示例#1文件:
generators.py项目:
blacktorn/django-autofixture
def generate(self):
import uuid
import shutil
from django.conf import settings
from placeholder import PlaceHolderImage
width, height = random.choice([(100,100), (200,300), (400,600)])
filename = '{0}x{1}.png'.format(width, height)
file_path = os.path.join(settings.MEDIA_ROOT, '_autofixture/', filename)
if not os.path.isdir(os.path.join(settings.MEDIA_ROOT, '_autofixture/')):
os.makedirs(os.path.join(settings.MEDIA_ROOT, '_autofixture/')) # ensure that _autofixture folder exists
if os.path.isfile(file_path):
suffix = str(uuid.uuid4())
new_file_path = os.path.join(settings.MEDIA_ROOT, '_autofixture/', "_".join([suffix, filename]))
shutil.copyfile(file_path, new_file_path)
file_path = new_file_path
else:
img = PlaceHolderImage(width = width, height = height, path = file_path)
img.save_image()
return relpath(file_path, settings.MEDIA_ROOT)
示例#2文件:
generators.py项目:
genba/django-autofixture
def generate(self):
import uuid
from django.conf import settings
from placeholder import PlaceHolderImage
width, height = random.choice(self.sizes)
# Ensure that _autofixture folder exists.
if not os.path.isdir(os.path.join(settings.MEDIA_ROOT, self.path)):
os.makedirs(os.path.join(settings.MEDIA_ROOT, self.path))
i = 0
filename = self.filename.format(width=width, height=height, suffix=i)
filepath = os.path.join(settings.MEDIA_ROOT, self.path, filename)
while os.path.exists(filepath):
i += 1
filename = self.filename.format(width=width, height=height, suffix=i)
filepath = os.path.join(settings.MEDIA_ROOT, self.path, filename)
img = PlaceHolderImage(width=width, height=height, path=filepath)
img.save_image()
return relpath(filepath, settings.MEDIA_ROOT)
示例#3文件:
__init__.py项目:
Visgean/python-placeholder
def test_odd_dimensions(self):
placeholder = PlaceHolderImage(1, 1, self.filename)
placeholder.save_image()
imagefile = Image.open(self.filename)
self.assertEqual(imagefile.size, (1, 1))
placeholder = PlaceHolderImage(201, 199, self.filename)
placeholder.save_image()
imagefile = Image.open(self.filename)
self.assertEqual(imagefile.size, (201, 199))
示例#4文件:
__init__.py项目:
Visgean/python-placeholder
def test_dimensions(self):
placeholder = PlaceHolderImage(200, 100, self.filename)
placeholder.save_image()
imagefile = Image.open(self.filename)
self.assertEqual(imagefile.size, (200, 100))
示例#5文件:
__init__.py项目:
Visgean/python-placeholder
def test_create(self):
placeholder = PlaceHolderImage(200, 100, self.filename)
placeholder.save_image()