Merge pull request #31 from chun-awa/main
Use github pages as artifact output
This commit is contained in:
commit
7c91db8229
43
.github/workflows/pack_img.yaml
vendored
43
.github/workflows/pack_img.yaml
vendored
@ -7,18 +7,25 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main # 当对 main 分支创建 PR 时触发
|
- main # 当对 main 分支创建 PR 时触发
|
||||||
permissions:
|
workflow_dispatch:
|
||||||
contents: write # 允许对代码库的写入权限
|
|
||||||
jobs:
|
jobs:
|
||||||
run-script:
|
run-script:
|
||||||
|
permissions:
|
||||||
|
contents: write # 允许对代码库的写入权限
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
environment:
|
||||||
|
name: github-pages
|
||||||
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
runs-on: ubuntu-latest # 使用最新的 Ubuntu 运行环境
|
runs-on: ubuntu-latest # 使用最新的 Ubuntu 运行环境
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3 # 检出当前仓库代码
|
uses: actions/checkout@v4 # 检出当前仓库代码
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.x' # 设置 Python 版本
|
python-version: '3.x' # 设置 Python 版本
|
||||||
|
|
||||||
@ -29,26 +36,14 @@ jobs:
|
|||||||
|
|
||||||
- name: Run image stitching script
|
- name: Run image stitching script
|
||||||
run: |
|
run: |
|
||||||
python auto_pack_img.py # 运行你的 Python 脚本(替换为你的脚本文件名)
|
mkdir images
|
||||||
|
./auto_pack_img.py
|
||||||
|
|
||||||
- name: Save stitched image as artifact
|
- name: Upload Pages artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: auto_img_zh_cn # 上传生成的图片作为 artifact
|
path: images
|
||||||
path: auto_img_zh_cn.png # 替换为你生成图片的路径
|
|
||||||
|
|
||||||
- name: Save stitched image as artifact
|
- name: Deploy to GitHub Pages
|
||||||
uses: actions/upload-artifact@v3
|
id: deployment
|
||||||
with:
|
uses: actions/deploy-pages@v4
|
||||||
name: auto_img_en # 上传生成的图片作为 artifact
|
|
||||||
path: auto_img_en.png # 替换为你生成图片的路径
|
|
||||||
- name: Commit and push updated file
|
|
||||||
run: |
|
|
||||||
git config --global user.name "github-actions[bot]"
|
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
git add auto_img_zh_cn.png # 添加你想要提交的文件
|
|
||||||
git add auto_img_en.png
|
|
||||||
git commit -m "Update file with new data"
|
|
||||||
git push origin main # 推送更改回 main 分支
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 使用 GitHub 提供的 Token 推送更改
|
|
||||||
|
10
README.md
10
README.md
@ -1,15 +1,17 @@
|
|||||||
# mcmeme
|
# mcmeme
|
||||||
|
|
||||||
欢迎各位提交[Pull Request](https://github.com/LIPiston/mcmeme/pulls)来扩展这张图
|
欢迎各位提交[Pull Request](https://github.com/LIPiston/mcmeme/pulls)来扩展这张图
|
||||||

|
|
||||||
|
|
||||||
Pull Request的时候提交小图即可 大图太容易冲突了
|
Pull Request的时候提交小图即可 大图太容易冲突了
|
||||||
|
|
||||||
## 自动生成的大图
|
|
||||||

|
|
||||||

|
|
||||||
[QQ群](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=GSK0q5Be9BtgPh-7UDEgw1XUc9eNlb_E&authKey=s54nZ9lIbjETFV2sQj65vJHoH04tg%2Bst%2FB%2Fo0WgVTyRGo%2BxL0ZPw8%2BHX3oNnr%2FIo&noverify=0&group_code=810025413)
|
[QQ群](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=GSK0q5Be9BtgPh-7UDEgw1XUc9eNlb_E&authKey=s54nZ9lIbjETFV2sQj65vJHoH04tg%2Bst%2FB%2Fo0WgVTyRGo%2BxL0ZPw8%2BHX3oNnr%2FIo&noverify=0&group_code=810025413)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 自动生成的大图
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
## 梦开始的地方
|
## 梦开始的地方
|
||||||
|
|
||||||
### 原创
|
### 原创
|
||||||
|
BIN
auto_img.png
BIN
auto_img.png
Binary file not shown.
Before Width: | Height: | Size: 9.9 MiB |
BIN
auto_img_en.png
BIN
auto_img_en.png
Binary file not shown.
Before Width: | Height: | Size: 514 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.2 MiB |
271
auto_pack_img.py
Normal file → Executable file
271
auto_pack_img.py
Normal file → Executable file
@ -1,135 +1,136 @@
|
|||||||
import random
|
#!/usr/bin/env python3
|
||||||
|
import random
|
||||||
import cv2
|
|
||||||
import numpy as np
|
import cv2
|
||||||
import os
|
import numpy as np
|
||||||
|
import os
|
||||||
|
|
||||||
class Node:
|
|
||||||
def __init__(self, x, y, width, height):
|
class Node:
|
||||||
self.x = x
|
def __init__(self, x, y, width, height):
|
||||||
self.y = y
|
self.x = x
|
||||||
self.width = width
|
self.y = y
|
||||||
self.height = height
|
self.width = width
|
||||||
self.used = False
|
self.height = height
|
||||||
self.right = None
|
self.used = False
|
||||||
self.down = None
|
self.right = None
|
||||||
|
self.down = None
|
||||||
|
|
||||||
def find_node(root, width, height):
|
|
||||||
if root.used:
|
def find_node(root, width, height):
|
||||||
return find_node(root.right, width, height) or find_node(root.down, width, height)
|
if root.used:
|
||||||
elif width <= root.width and height <= root.height:
|
return find_node(root.right, width, height) or find_node(root.down, width, height)
|
||||||
return root
|
elif width <= root.width and height <= root.height:
|
||||||
else:
|
return root
|
||||||
return None
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def split_node(node, width, height):
|
|
||||||
node.used = True
|
def split_node(node, width, height):
|
||||||
node.down = Node(node.x, node.y + height, node.width, node.height - height)
|
node.used = True
|
||||||
node.right = Node(node.x + width, node.y, node.width - width, height)
|
node.down = Node(node.x, node.y + height, node.width, node.height - height)
|
||||||
return node
|
node.right = Node(node.x + width, node.y, node.width - width, height)
|
||||||
|
return node
|
||||||
|
|
||||||
def grow_node(root, width, height):
|
|
||||||
can_grow_down = (width <= root.width)
|
def grow_node(root, width, height):
|
||||||
can_grow_right = (height <= root.height)
|
can_grow_down = (width <= root.width)
|
||||||
|
can_grow_right = (height <= root.height)
|
||||||
should_grow_right = can_grow_right and (root.height >= (root.width + width))
|
|
||||||
should_grow_down = can_grow_down and (root.width >= (root.height + height))
|
should_grow_right = can_grow_right and (root.height >= (root.width + width))
|
||||||
|
should_grow_down = can_grow_down and (root.width >= (root.height + height))
|
||||||
if should_grow_right:
|
|
||||||
return grow_right(root, width, height)
|
if should_grow_right:
|
||||||
elif should_grow_down:
|
return grow_right(root, width, height)
|
||||||
return grow_down(root, width, height)
|
elif should_grow_down:
|
||||||
elif can_grow_right:
|
return grow_down(root, width, height)
|
||||||
return grow_right(root, width, height)
|
elif can_grow_right:
|
||||||
elif can_grow_down:
|
return grow_right(root, width, height)
|
||||||
return grow_down(root, width, height)
|
elif can_grow_down:
|
||||||
else:
|
return grow_down(root, width, height)
|
||||||
root.width=root.width+width//2
|
else:
|
||||||
root.height=root.height+height//2
|
root.width=root.width+width//2
|
||||||
return grow_node(root, width, height)
|
root.height=root.height+height//2
|
||||||
|
return grow_node(root, width, height)
|
||||||
|
|
||||||
def grow_right(root, width, height):
|
|
||||||
new_root = Node(0, 0, root.width + width, root.height)
|
def grow_right(root, width, height):
|
||||||
new_root.used = True
|
new_root = Node(0, 0, root.width + width, root.height)
|
||||||
new_root.down = root
|
new_root.used = True
|
||||||
new_root.right = Node(root.width, 0, width, root.height)
|
new_root.down = root
|
||||||
return new_root if find_node(new_root, width, height) else None
|
new_root.right = Node(root.width, 0, width, root.height)
|
||||||
|
return new_root if find_node(new_root, width, height) else None
|
||||||
|
|
||||||
def grow_down(root, width, height):
|
|
||||||
new_root = Node(0, 0, root.width, root.height + height)
|
def grow_down(root, width, height):
|
||||||
new_root.used = True
|
new_root = Node(0, 0, root.width, root.height + height)
|
||||||
new_root.right = root
|
new_root.used = True
|
||||||
new_root.down = Node(0, root.height, root.width, height)
|
new_root.right = root
|
||||||
return new_root if find_node(new_root, width, height) else None
|
new_root.down = Node(0, root.height, root.width, height)
|
||||||
|
return new_root if find_node(new_root, width, height) else None
|
||||||
|
|
||||||
def stitch_images_bin_packing(images):
|
|
||||||
|
def stitch_images_bin_packing(images):
|
||||||
root = Node(0, 0, images[0].shape[1], images[0].shape[0])
|
|
||||||
|
root = Node(0, 0, images[0].shape[1], images[0].shape[0])
|
||||||
positions = []
|
|
||||||
|
positions = []
|
||||||
for img in images:
|
|
||||||
node = find_node(root, img.shape[1], img.shape[0])
|
for img in images:
|
||||||
if node:
|
node = find_node(root, img.shape[1], img.shape[0])
|
||||||
split_node(node, img.shape[1], img.shape[0])
|
if node:
|
||||||
else:
|
split_node(node, img.shape[1], img.shape[0])
|
||||||
root = grow_node(root, img.shape[1], img.shape[0])
|
else:
|
||||||
node = find_node(root, img.shape[1], img.shape[0])
|
root = grow_node(root, img.shape[1], img.shape[0])
|
||||||
split_node(node, img.shape[1], img.shape[0])
|
node = find_node(root, img.shape[1], img.shape[0])
|
||||||
positions.append((node.x, node.y))
|
split_node(node, img.shape[1], img.shape[0])
|
||||||
|
positions.append((node.x, node.y))
|
||||||
|
|
||||||
# stitched_image = np.zeros((root.height, root.width, 3), dtype=np.uint8)
|
|
||||||
stitched_image = np.full((root.height, root.width, 3),255, dtype=np.uint8)
|
# stitched_image = np.zeros((root.height, root.width, 3), dtype=np.uint8)
|
||||||
|
stitched_image = np.full((root.height, root.width, 3),255, dtype=np.uint8)
|
||||||
|
|
||||||
for pos, img in zip(positions, images):
|
|
||||||
x, y = pos
|
for pos, img in zip(positions, images):
|
||||||
stitched_image[y:y + img.shape[0], x:x + img.shape[1]] = img
|
x, y = pos
|
||||||
|
stitched_image[y:y + img.shape[0], x:x + img.shape[1]] = img
|
||||||
return stitched_image
|
|
||||||
|
return stitched_image
|
||||||
|
|
||||||
|
|
||||||
def load_images_from_folder(folder,max_height=768,max_width=768):
|
|
||||||
images = []
|
def load_images_from_folder(folder,max_height=768,max_width=768):
|
||||||
for filename in os.listdir(folder):
|
images = []
|
||||||
img = cv2.imread(os.path.join(folder, filename))
|
for filename in os.listdir(folder):
|
||||||
if img is not None:
|
img = cv2.imread(os.path.join(folder, filename))
|
||||||
if max_height is not None and max_width is not None:
|
if img is not None:
|
||||||
if img.shape[0] > max_height or img.shape[1] > max_width:
|
if max_height is not None and max_width is not None:
|
||||||
scw=img.shape[1]/max_width
|
if img.shape[0] > max_height or img.shape[1] > max_width:
|
||||||
sch=img.shape[0]/max_height
|
scw=img.shape[1]/max_width
|
||||||
mac=max(scw,sch)
|
sch=img.shape[0]/max_height
|
||||||
img = cv2.resize(img, (int(img.shape[1]//mac),int(img.shape[0]//mac)))
|
mac=max(scw,sch)
|
||||||
# img = cv2.resize(img, (min(img.shape[1], max_width), min(img.shape[0], max_height)))
|
img = cv2.resize(img, (int(img.shape[1]//mac),int(img.shape[0]//mac)))
|
||||||
# img = cv2.resize(img, (min(img.shape[1], max_width), min(img.shape[0], max_height)))
|
# img = cv2.resize(img, (min(img.shape[1], max_width), min(img.shape[0], max_height)))
|
||||||
images.append(img)
|
# img = cv2.resize(img, (min(img.shape[1], max_width), min(img.shape[0], max_height)))
|
||||||
random.shuffle(images)
|
images.append(img)
|
||||||
return images
|
random.shuffle(images)
|
||||||
|
return images
|
||||||
|
|
||||||
|
|
||||||
folder = 'zh_cn'
|
|
||||||
images = load_images_from_folder(folder)
|
folder = 'zh_cn'
|
||||||
|
images = load_images_from_folder(folder)
|
||||||
stitched_image = stitch_images_bin_packing(images)
|
|
||||||
|
stitched_image = stitch_images_bin_packing(images)
|
||||||
|
|
||||||
cv2.imwrite('auto_img_zh_cn.png', stitched_image)
|
|
||||||
|
cv2.imwrite('images/auto_img_zh_cn.png', stitched_image)
|
||||||
|
|
||||||
folder = 'en'
|
|
||||||
images = load_images_from_folder(folder)
|
folder = 'en'
|
||||||
|
images = load_images_from_folder(folder)
|
||||||
stitched_image = stitch_images_bin_packing(images)
|
|
||||||
|
stitched_image = stitch_images_bin_packing(images)
|
||||||
|
|
||||||
cv2.imwrite('auto_img_en.png', stitched_image)
|
|
||||||
|
cv2.imwrite('images/auto_img_en.png', stitched_image)
|
||||||
|
BIN
latest.png
BIN
latest.png
Binary file not shown.
Before Width: | Height: | Size: 3.2 MiB |
Loading…
Reference in New Issue
Block a user