29.12.2021.1
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.pyc
|
||||
__pycache__
|
87
MockupModule/__init__.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
import logging
|
||||
import os
|
||||
from importlib import import_module
|
||||
|
||||
from typing import List
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from MockupModule import templates
|
||||
from MockupModule.utils import random_string
|
||||
|
||||
generated_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'generated')
|
||||
if not os.path.exists(generated_path):
|
||||
os.makedirs(generated_path)
|
||||
|
||||
|
||||
class MockupEngineer:
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger('MockupEngineer')
|
||||
self.templates: List[templates.Template] = []
|
||||
|
||||
for template in templates.ALL_TEMPLATES:
|
||||
self.templates.append(getattr(
|
||||
import_module(name='MockupModule.templates.' + template,
|
||||
package='MockupModule.templates.' + template + '.Device'), 'Device')())
|
||||
|
||||
def screenshot_resize(self, screenshot: str, width: int, height: int) -> str:
|
||||
name = '{}/screenshot{}.png'.format(generated_path, random_string(16))
|
||||
img = Image.open(screenshot)
|
||||
img = img.resize((width, height), Image.ANTIALIAS)
|
||||
img.save(name)
|
||||
|
||||
return name
|
||||
|
||||
def get_templates(self) -> dict:
|
||||
dicted = dict()
|
||||
for template in self.templates:
|
||||
if template.type in dicted.keys():
|
||||
dicted[template.type].append(template)
|
||||
else:
|
||||
dicted[template.type] = [template]
|
||||
return dicted
|
||||
|
||||
def generate(self, template: templates.Template, screenshot: str, color: str = None, orientation: str = None):
|
||||
self.logger.info(
|
||||
'Generating: {}'.format(
|
||||
', '.join(
|
||||
[': '.join([str(a).upper(), str(b)]) for a, b in template.__dict__.items()])))
|
||||
|
||||
if not orientation:
|
||||
img = Image.open(screenshot)
|
||||
width, height = img.size
|
||||
orientation = 'portrait' if height > width or height == width else 'landscape'
|
||||
|
||||
if orientation == 'portrait':
|
||||
screen_width = template.portrait_resolution.width
|
||||
screen_height = template.portrait_resolution.height
|
||||
width_coordinate = template.__portrait_width__
|
||||
height_coordinate = template.__portrait_height__
|
||||
else:
|
||||
screen_width = template.landscape_resolution.width
|
||||
screen_height = template.landscape_resolution.height
|
||||
width_coordinate = template.__landscape_width__
|
||||
height_coordinate = template.__landscape_height__
|
||||
|
||||
screenshot = self.screenshot_resize(screenshot, screen_width, screen_height)
|
||||
|
||||
for template_color in template.colors:
|
||||
if template_color.color == color:
|
||||
template_path = template_color.portrait_path \
|
||||
if orientation == 'portrait' else template_color.landscape_path
|
||||
break
|
||||
else:
|
||||
template_path = template.colors[-1].portrait_path \
|
||||
if orientation == 'portrait' else template.colors[-1].landscape_path
|
||||
|
||||
name = '{}/mockup{}.png'.format(generated_path, random_string(16))
|
||||
|
||||
template_img = Image.open(template_path)
|
||||
mask_img = Image.new('RGBA', template_img.size, (0, 0, 0, 0))
|
||||
screenshot_img = Image.open(screenshot)
|
||||
mask_img.paste(screenshot_img, (width_coordinate, height_coordinate))
|
||||
mask_img.paste(template_img, (0, 0), template_img)
|
||||
|
||||
mask_img.save(name)
|
||||
|
||||
return name
|
28
MockupModule/__main__.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import os
|
||||
|
||||
from MockupModule import MockupEngineer
|
||||
|
||||
|
||||
def main():
|
||||
mockup = MockupEngineer()
|
||||
i = 0
|
||||
for template in mockup.templates:
|
||||
print('[{}] {} {} ({})'.format(i, template.manufacturer, template.name, template.year))
|
||||
i += 1
|
||||
template = mockup.templates[int(input('Choose device: '))]
|
||||
print('- - - - - - - - - -')
|
||||
i = 0
|
||||
for color in template.colors:
|
||||
print('[{}] {}'.format(i, color.color))
|
||||
i += 1
|
||||
color = template.colors[int(input('Choose color: '))].color
|
||||
print('- - - - - - - - - -')
|
||||
screenshot = input('Enter path to screenshot: ')
|
||||
print('- - - - - - - - - -\nWorking...')
|
||||
mockup = mockup.generate(template, screenshot, color)
|
||||
print('- - - - - - - - - -\nSuccess: {}'.format(mockup))
|
||||
os.system('open {}'.format(mockup))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
49
MockupModule/templates/__init__.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import os
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
|
||||
templates_path = os.path.join("/".join(os.path.dirname(os.path.abspath(__file__)).split('/')[:-1]), 'templates')
|
||||
|
||||
|
||||
def __list_all_templates():
|
||||
all_templates = [x.name for x in Path(templates_path).iterdir()
|
||||
if x.is_dir() and not str(x).startswith('__') and not str(x).endswith('__')]
|
||||
return all_templates
|
||||
|
||||
|
||||
ALL_TEMPLATES = sorted(__list_all_templates())
|
||||
__all__ = ALL_TEMPLATES + ["ALL_TEMPLATES"]
|
||||
|
||||
|
||||
@dataclass(frozen=False)
|
||||
class TemplateResolution:
|
||||
width: int = field(default_factory=int)
|
||||
height: int = field(default_factory=int)
|
||||
|
||||
|
||||
@dataclass(frozen=False)
|
||||
class TemplateColor:
|
||||
color: str = ''
|
||||
portrait_path: str = field(default_factory=str)
|
||||
landscape_path: str = field(default_factory=str)
|
||||
|
||||
|
||||
@dataclass(frozen=False)
|
||||
class Template:
|
||||
manufacturer: str = field(default_factory=str)
|
||||
name: str = field(default_factory=str)
|
||||
type: str = field(default_factory=str)
|
||||
year: int = field(default_factory=int)
|
||||
example_path: str = field(default_factory=str)
|
||||
portrait_resolution: TemplateResolution = field(default_factory=TemplateResolution)
|
||||
landscape_resolution: TemplateResolution = field(default_factory=TemplateResolution)
|
||||
|
||||
colors: List[TemplateColor] = field(default_factory=list)
|
||||
|
||||
__portrait_width__: int = field(default_factory=int)
|
||||
__portrait_height__: int = field(default_factory=int)
|
||||
__landscape_width__: int = field(default_factory=int)
|
||||
__landscape_height__: int = field(default_factory=int)
|
49
MockupModule/templates/iphone12/__init__.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone 12'
|
||||
self.type = 'phone'
|
||||
self.year = 2020
|
||||
self.example_path = templates_path + '/iphone12/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=1170, height=2532)
|
||||
self.landscape_resolution = TemplateResolution(width=2532, height=1170)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Black',
|
||||
portrait_path=templates_path + '/iphone12/black/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12/black/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Blue',
|
||||
portrait_path=templates_path + '/iphone12/blue/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12/blue/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Green',
|
||||
portrait_path=templates_path + '/iphone12/green/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12/green/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='PRODUCT RED',
|
||||
portrait_path=templates_path + '/iphone12/red/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12/red/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='White',
|
||||
portrait_path=templates_path + '/iphone12/white/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12/white/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 180
|
||||
self.__portrait_height__ = 180
|
||||
self.__landscape_width__ = 180
|
||||
self.__landscape_height__ = 180
|
||||
|
BIN
MockupModule/templates/iphone12/black/landscape.png
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
MockupModule/templates/iphone12/black/portrait.png
Normal file
After Width: | Height: | Size: 289 KiB |
BIN
MockupModule/templates/iphone12/blue/landscape.png
Normal file
After Width: | Height: | Size: 251 KiB |
BIN
MockupModule/templates/iphone12/blue/portrait.png
Normal file
After Width: | Height: | Size: 311 KiB |
BIN
MockupModule/templates/iphone12/example.png
Normal file
After Width: | Height: | Size: 195 KiB |
BIN
MockupModule/templates/iphone12/green/landscape.png
Normal file
After Width: | Height: | Size: 247 KiB |
BIN
MockupModule/templates/iphone12/green/portrait.png
Normal file
After Width: | Height: | Size: 301 KiB |
BIN
MockupModule/templates/iphone12/red/landscape.png
Normal file
After Width: | Height: | Size: 249 KiB |
BIN
MockupModule/templates/iphone12/red/portrait.png
Normal file
After Width: | Height: | Size: 300 KiB |
BIN
MockupModule/templates/iphone12/white/landscape.png
Normal file
After Width: | Height: | Size: 264 KiB |
BIN
MockupModule/templates/iphone12/white/portrait.png
Normal file
After Width: | Height: | Size: 319 KiB |
49
MockupModule/templates/iphone12mini/__init__.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone 12 Mini'
|
||||
self.type = 'phone'
|
||||
self.year = 2020
|
||||
self.example_path = templates_path + '/iphone12mini/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=1080, height=2340)
|
||||
self.landscape_resolution = TemplateResolution(width=2340, height=1080)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Black',
|
||||
portrait_path=templates_path + '/iphone12mini/black/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12mini/black/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Blue',
|
||||
portrait_path=templates_path + '/iphone12mini/blue/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12mini/blue/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Green',
|
||||
portrait_path=templates_path + '/iphone12mini/green/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12mini/green/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='PRODUCT RED',
|
||||
portrait_path=templates_path + '/iphone12mini/red/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12mini/red/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='White',
|
||||
portrait_path=templates_path + '/iphone12mini/white/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12mini/white/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 160
|
||||
self.__portrait_height__ = 160
|
||||
self.__landscape_width__ = 180
|
||||
self.__landscape_height__ = 180
|
||||
|
BIN
MockupModule/templates/iphone12mini/black/landscape.png
Normal file
After Width: | Height: | Size: 220 KiB |
BIN
MockupModule/templates/iphone12mini/black/portrait.png
Normal file
After Width: | Height: | Size: 264 KiB |
BIN
MockupModule/templates/iphone12mini/blue/landscape.png
Normal file
After Width: | Height: | Size: 226 KiB |
BIN
MockupModule/templates/iphone12mini/blue/portrait.png
Normal file
After Width: | Height: | Size: 278 KiB |
BIN
MockupModule/templates/iphone12mini/example.png
Normal file
After Width: | Height: | Size: 208 KiB |
BIN
MockupModule/templates/iphone12mini/green/landscape.png
Normal file
After Width: | Height: | Size: 227 KiB |
BIN
MockupModule/templates/iphone12mini/green/portrait.png
Normal file
After Width: | Height: | Size: 272 KiB |
BIN
MockupModule/templates/iphone12mini/red/landscape.png
Normal file
After Width: | Height: | Size: 224 KiB |
BIN
MockupModule/templates/iphone12mini/red/portrait.png
Normal file
After Width: | Height: | Size: 272 KiB |
BIN
MockupModule/templates/iphone12mini/white/landscape.png
Normal file
After Width: | Height: | Size: 248 KiB |
BIN
MockupModule/templates/iphone12mini/white/portrait.png
Normal file
After Width: | Height: | Size: 304 KiB |
44
MockupModule/templates/iphone12pro/__init__.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone 12 Pro'
|
||||
self.type = 'phone'
|
||||
self.year = 2020
|
||||
self.example_path = templates_path + '/iphone12pro/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=1170, height=2532)
|
||||
self.landscape_resolution = TemplateResolution(width=2532, height=1170)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Gold',
|
||||
portrait_path=templates_path + '/iphone12pro/gold/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12pro/gold/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Graphite',
|
||||
portrait_path=templates_path + '/iphone12pro/graphite/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12pro/graphite/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Pacific Blue',
|
||||
portrait_path=templates_path + '/iphone12pro/pacificblue/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12pro/pacificblue/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Silver',
|
||||
portrait_path=templates_path + '/iphone12pro/silver/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12pro/silver/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 180
|
||||
self.__portrait_height__ = 180
|
||||
self.__landscape_width__ = 180
|
||||
self.__landscape_height__ = 180
|
||||
|
BIN
MockupModule/templates/iphone12pro/example.png
Normal file
After Width: | Height: | Size: 218 KiB |
BIN
MockupModule/templates/iphone12pro/gold/landscape.png
Normal file
After Width: | Height: | Size: 260 KiB |
BIN
MockupModule/templates/iphone12pro/gold/portrait.png
Normal file
After Width: | Height: | Size: 318 KiB |
BIN
MockupModule/templates/iphone12pro/graphite/landscape.png
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
MockupModule/templates/iphone12pro/graphite/portrait.png
Normal file
After Width: | Height: | Size: 285 KiB |
BIN
MockupModule/templates/iphone12pro/pacificblue/landscape.png
Normal file
After Width: | Height: | Size: 248 KiB |
BIN
MockupModule/templates/iphone12pro/pacificblue/portrait.png
Normal file
After Width: | Height: | Size: 301 KiB |
BIN
MockupModule/templates/iphone12pro/silver/landscape.png
Normal file
After Width: | Height: | Size: 248 KiB |
BIN
MockupModule/templates/iphone12pro/silver/portrait.png
Normal file
After Width: | Height: | Size: 301 KiB |
44
MockupModule/templates/iphone12promax/__init__.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone 12 Pro Max'
|
||||
self.type = 'phone'
|
||||
self.year = 2020
|
||||
self.example_path = templates_path + '/iphone12promax/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=1284, height=2778)
|
||||
self.landscape_resolution = TemplateResolution(width=2778, height=1284)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Gold',
|
||||
portrait_path=templates_path + '/iphone12promax/gold/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12promax/gold/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Graphite',
|
||||
portrait_path=templates_path + '/iphone12promax/graphite/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12promax/graphite/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Pacific Blue',
|
||||
portrait_path=templates_path + '/iphone12promax/pacificblue/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12promax/pacificblue/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Silver',
|
||||
portrait_path=templates_path + '/iphone12promax/silver/portrait.png',
|
||||
landscape_path=templates_path + '/iphone12promax/silver/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 200
|
||||
self.__portrait_height__ = 200
|
||||
self.__landscape_width__ = 200
|
||||
self.__landscape_height__ = 200
|
||||
|
BIN
MockupModule/templates/iphone12promax/example.png
Normal file
After Width: | Height: | Size: 248 KiB |
BIN
MockupModule/templates/iphone12promax/gold/landscape.png
Normal file
After Width: | Height: | Size: 300 KiB |
BIN
MockupModule/templates/iphone12promax/gold/portrait.png
Normal file
After Width: | Height: | Size: 367 KiB |
BIN
MockupModule/templates/iphone12promax/graphite/landscape.png
Normal file
After Width: | Height: | Size: 285 KiB |
BIN
MockupModule/templates/iphone12promax/graphite/portrait.png
Normal file
After Width: | Height: | Size: 344 KiB |
BIN
MockupModule/templates/iphone12promax/pacificblue/landscape.png
Normal file
After Width: | Height: | Size: 287 KiB |
BIN
MockupModule/templates/iphone12promax/pacificblue/portrait.png
Normal file
After Width: | Height: | Size: 343 KiB |
BIN
MockupModule/templates/iphone12promax/silver/landscape.png
Normal file
After Width: | Height: | Size: 290 KiB |
BIN
MockupModule/templates/iphone12promax/silver/portrait.png
Normal file
After Width: | Height: | Size: 347 KiB |
39
MockupModule/templates/iphonese2020/__init__.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone SE'
|
||||
self.type = 'phone'
|
||||
self.year = 2020
|
||||
self.example_path = templates_path + '/iphonese2020/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=750, height=1334)
|
||||
self.landscape_resolution = TemplateResolution(width=1334, height=750)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Black',
|
||||
portrait_path=templates_path + '/iphonese2020/black/portrait.png',
|
||||
landscape_path=templates_path + '/iphonese2020/black/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='PRODUCT RED',
|
||||
portrait_path=templates_path + '/iphonese2020/red/portrait.png',
|
||||
landscape_path=templates_path + '/iphonese2020/red/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='White',
|
||||
portrait_path=templates_path + '/iphonese2020/white/portrait.png',
|
||||
landscape_path=templates_path + '/iphonese2020/white/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 150
|
||||
self.__portrait_height__ = 300
|
||||
self.__landscape_width__ = 300
|
||||
self.__landscape_height__ = 140
|
||||
|
BIN
MockupModule/templates/iphonese2020/black/landscape.png
Normal file
After Width: | Height: | Size: 159 KiB |
BIN
MockupModule/templates/iphonese2020/black/portrait.png
Normal file
After Width: | Height: | Size: 222 KiB |
0
MockupModule/templates/iphonese2020/example.png
Normal file
BIN
MockupModule/templates/iphonese2020/red/landscape.png
Normal file
After Width: | Height: | Size: 175 KiB |
BIN
MockupModule/templates/iphonese2020/red/portrait.png
Normal file
After Width: | Height: | Size: 241 KiB |
BIN
MockupModule/templates/iphonese2020/white/landscape.png
Normal file
After Width: | Height: | Size: 166 KiB |
BIN
MockupModule/templates/iphonese2020/white/portrait.png
Normal file
After Width: | Height: | Size: 231 KiB |
54
MockupModule/templates/iphonexr/__init__.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from MockupModule.templates import templates_path, TemplateResolution, TemplateColor, Template
|
||||
|
||||
|
||||
@dataclass
|
||||
class Device(Template):
|
||||
def __post_init__(self):
|
||||
self.manufacturer = 'Apple'
|
||||
self.name = 'iPhone Xr'
|
||||
self.type = 'phone'
|
||||
self.year = 2018
|
||||
self.example_path = templates_path + '/iphonexr/example.png'
|
||||
self.portrait_resolution = TemplateResolution(width=828, height=1792)
|
||||
self.landscape_resolution = TemplateResolution(width=1792, height=828)
|
||||
|
||||
self.colors = [
|
||||
TemplateColor(
|
||||
color='Blue',
|
||||
portrait_path=templates_path + '/iphonexr/blue/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/blue/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Coral',
|
||||
portrait_path=templates_path + '/iphonexr/coral/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/coral/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='PRODUCT RED',
|
||||
portrait_path=templates_path + '/iphonexr/red/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/red/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Silver',
|
||||
portrait_path=templates_path + '/iphonexr/silver/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/silver/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Space Gray',
|
||||
portrait_path=templates_path + '/iphonexr/spacegray/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/spacegray/landscape.png',
|
||||
),
|
||||
TemplateColor(
|
||||
color='Yellow',
|
||||
portrait_path=templates_path + '/iphonexr/yellow/portrait.png',
|
||||
landscape_path=templates_path + '/iphonexr/yellow/landscape.png',
|
||||
)
|
||||
]
|
||||
|
||||
self.__portrait_width__ = 110
|
||||
self.__portrait_height__ = 110
|
||||
self.__landscape_width__ = 110
|
||||
self.__landscape_height__ = 110
|
||||
|
BIN
MockupModule/templates/iphonexr/blue/landscape.png
Normal file
After Width: | Height: | Size: 222 KiB |
BIN
MockupModule/templates/iphonexr/blue/portrait.png
Normal file
After Width: | Height: | Size: 266 KiB |
BIN
MockupModule/templates/iphonexr/coral/landscape.png
Normal file
After Width: | Height: | Size: 221 KiB |
BIN
MockupModule/templates/iphonexr/coral/portrait.png
Normal file
After Width: | Height: | Size: 264 KiB |
BIN
MockupModule/templates/iphonexr/example.png
Normal file
After Width: | Height: | Size: 208 KiB |
BIN
MockupModule/templates/iphonexr/red/landscape.png
Normal file
After Width: | Height: | Size: 220 KiB |
BIN
MockupModule/templates/iphonexr/red/portrait.png
Normal file
After Width: | Height: | Size: 262 KiB |
BIN
MockupModule/templates/iphonexr/silver/landscape.png
Normal file
After Width: | Height: | Size: 185 KiB |
BIN
MockupModule/templates/iphonexr/silver/portrait.png
Normal file
After Width: | Height: | Size: 220 KiB |
BIN
MockupModule/templates/iphonexr/spacegray/landscape.png
Normal file
After Width: | Height: | Size: 213 KiB |
BIN
MockupModule/templates/iphonexr/spacegray/portrait.png
Normal file
After Width: | Height: | Size: 265 KiB |
BIN
MockupModule/templates/iphonexr/yellow/landscape.png
Normal file
After Width: | Height: | Size: 222 KiB |
BIN
MockupModule/templates/iphonexr/yellow/portrait.png
Normal file
After Width: | Height: | Size: 268 KiB |
29
MockupModule/utils.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import asyncio
|
||||
import functools
|
||||
import random
|
||||
import string
|
||||
|
||||
from FlowyModule.models import Track
|
||||
|
||||
|
||||
def run_sync(func, *args, **kwargs):
|
||||
return asyncio.get_event_loop() \
|
||||
.run_in_executor(None,
|
||||
functools.partial(func,
|
||||
*args,
|
||||
**kwargs))
|
||||
|
||||
|
||||
def random_string(n: int):
|
||||
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))
|
||||
|
||||
|
||||
def prepare_name(name: str):
|
||||
symbols = '-1234567890qwertyuiopasdfghjklzxcvbnmйцукенгшщзхъфывапролджэячсмитьбю'
|
||||
return "".join([a if a.lower() in symbols else "-" for a in name])
|
||||
|
||||
|
||||
def gen_track_name(element: Track, container: str):
|
||||
return '{}-{}-{}.{}'.format(prepare_name(element.artists[0].name),
|
||||
prepare_name(element.title[:15]),
|
||||
random_string(6), container)
|