Skip to content

Commit

Permalink
Implement previewMockup function
Browse files Browse the repository at this point in the history
  • Loading branch information
YayunHuang committed Aug 16, 2024
1 parent 2caf66f commit 0c15bbb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions mockup_package/mockup/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .image import mockup as startMockup # noqa: F401
from .image import previewMockup # noqa: F401
42 changes: 42 additions & 0 deletions mockup_package/mockup/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,48 @@ async def mockup(location, device_id, original_img_path_list, device_info):
return output_img_path_list


# Now only the first orientation model is generated for preview
async def previewMockup(
location, device_id, original_img_path_list, device_info, preview_img_index=0
):
device_path_prefix = f"{location.split('/')[0]}//{location.split('/')[2]}"
device_mask_path_prefix = device_path_prefix + "/images/mockup_mask_templates/"
device_path_prefix += "/images/mockup_templates/"
device_path = "./device.png"
device_mask_path = "./device_mask.png"
output_img_path_list = []
for original_img_path in original_img_path_list:
ig = IG(original_img_path, device_id, device_info)
ig.create_fit_resolution_image()
try:
spec = list(ig.phone_models.get(device_id).get("mockups").values())[
preview_img_index
]
await process_response(
device_path_prefix + str(spec["image"]),
device_path,
)
await process_response(
device_mask_path_prefix + str(spec["image"]),
device_mask_path,
)
except Exception as e:
print(e, file=sys.stderr)
# js.errorBox(e)
raise
ig.create_fit_coord_image(spec)
deviceView = str(spec["image"]).split("-")[-1].split(".")[0]
path = (
f"{os.path.splitext(os.path.basename(original_img_path))[0]}"
+ f"-{deviceView}-preview.png"
)
ig.create_mockup_image(device_path, device_mask_path, path)
output_img_path_list.append([path, original_img_path, deviceView])

original_img_path_list.clear()
return output_img_path_list


async def download(url):
filename = Path(url).name
response = await pyfetch(url)
Expand Down
Binary file modified public/mockup.zip
Binary file not shown.

0 comments on commit 0c15bbb

Please sign in to comment.