release ohos
This commit is contained in:
113
scripts/add_image_border.py
Normal file
113
scripts/add_image_border.py
Normal file
@@ -0,0 +1,113 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from PIL import Image, ImageDraw, ImageFilter
|
||||
import os
|
||||
|
||||
def add_border_and_resize(input_path, output_path, target_size=(1920, 1080), border_color=(255, 255, 255), border_width=20):
|
||||
img = Image.open(input_path)
|
||||
original_width, original_height = img.size
|
||||
aspect_ratio = original_width / original_height
|
||||
target_aspect = target_size[0] / target_size[1]
|
||||
|
||||
if aspect_ratio > target_aspect:
|
||||
new_width = target_size[0] - border_width * 2
|
||||
new_height = int(new_width / aspect_ratio)
|
||||
else:
|
||||
new_height = target_size[1] - border_width * 2
|
||||
new_width = int(new_height * aspect_ratio)
|
||||
|
||||
img_resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
||||
output_img = Image.new('RGB', target_size, border_color)
|
||||
paste_x = (target_size[0] - new_width) // 2
|
||||
paste_y = (target_size[1] - new_height) // 2
|
||||
|
||||
shadow_offset = 8
|
||||
shadow_rect = [
|
||||
paste_x + shadow_offset,
|
||||
paste_y + shadow_offset,
|
||||
paste_x + new_width + shadow_offset,
|
||||
paste_y + new_height + shadow_offset
|
||||
]
|
||||
shadow_layer = Image.new('RGBA', target_size, (0, 0, 0, 0))
|
||||
shadow_draw = ImageDraw.Draw(shadow_layer)
|
||||
shadow_draw.rectangle(shadow_rect, fill=(0, 0, 0, 60))
|
||||
shadow_blurred = shadow_layer.filter(ImageFilter.GaussianBlur(radius=10))
|
||||
|
||||
final_image = Image.new('RGB', target_size, border_color)
|
||||
|
||||
if shadow_blurred.mode == 'RGBA':
|
||||
final_image.paste(shadow_blurred, (0, 0), shadow_blurred)
|
||||
else:
|
||||
final_rgb_shadow = shadow_blurred.convert('RGB')
|
||||
final_image.paste(final_rgb_shadow, (0, 0))
|
||||
|
||||
final_image.paste(img_resized, (paste_x, paste_y))
|
||||
|
||||
draw = ImageDraw.Draw(final_image)
|
||||
rect = [paste_x - 2, paste_y - 2, paste_x + new_width + 2, paste_y + new_height + 2]
|
||||
for i in range(3):
|
||||
offset = i + 1
|
||||
current_rect = [
|
||||
rect[0] - offset,
|
||||
rect[1] - offset,
|
||||
rect[2] + offset,
|
||||
rect[3] + offset
|
||||
]
|
||||
draw.rectangle(current_rect, outline=(180, 200, 220))
|
||||
|
||||
for i in range(border_width):
|
||||
current_rect = [
|
||||
rect[0] - i - 3,
|
||||
rect[1] - i - 3,
|
||||
rect[2] + i + 3,
|
||||
rect[3] + i + 3
|
||||
]
|
||||
alpha = int(255 * (1 - i / border_width))
|
||||
color_with_alpha = (200 + i*2, 210 + i*2, 230 + i*2)
|
||||
draw.rectangle(current_rect, outline=color_with_alpha)
|
||||
|
||||
final_image.save(output_path, quality=95)
|
||||
print(f'[OK] Processed: {os.path.basename(input_path)} -> {output_path}')
|
||||
return True
|
||||
|
||||
def main():
|
||||
input_files = [
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\1.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\2.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\3.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\4.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\5.jpg',
|
||||
]
|
||||
|
||||
output_dir = r'e:\project\flutter\f\mom_kitchen\docs\design\processed'
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
print('='*50)
|
||||
print('Image Border Processing Script')
|
||||
print(f'Target Size: 1920 x 1080 px')
|
||||
print(f'Processing: {len(input_files)} images')
|
||||
print('='*50)
|
||||
print()
|
||||
|
||||
success_count = 0
|
||||
for input_file in input_files:
|
||||
if os.path.exists(input_file):
|
||||
filename = os.path.basename(input_file)
|
||||
output_path = os.path.join(output_dir, f'bordered_{filename}')
|
||||
try:
|
||||
add_border_and_resize(input_file, output_path)
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
print(f'[ERROR] Failed to process: {filename} - {str(e)}')
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
else:
|
||||
print(f'[WARNING] File not found: {input_file}')
|
||||
|
||||
print()
|
||||
print('='*50)
|
||||
print(f'[DONE] Processed {success_count}/{len(input_files)} images successfully!')
|
||||
print(f'Output directory: {output_dir}')
|
||||
print('='*50)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
111
scripts/add_image_border_portrait.py
Normal file
111
scripts/add_image_border_portrait.py
Normal file
@@ -0,0 +1,111 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from PIL import Image, ImageDraw, ImageFilter
|
||||
import os
|
||||
|
||||
def add_border_and_resize(input_path, output_path, target_size=(1080, 1920), border_color=(255, 255, 255), border_width=20):
|
||||
img = Image.open(input_path)
|
||||
original_width, original_height = img.size
|
||||
aspect_ratio = original_width / original_height
|
||||
target_aspect = target_size[0] / target_size[1]
|
||||
|
||||
if aspect_ratio > target_aspect:
|
||||
new_width = target_size[0] - border_width * 2
|
||||
new_height = int(new_width / aspect_ratio)
|
||||
else:
|
||||
new_height = target_size[1] - border_width * 2
|
||||
new_width = int(new_height * aspect_ratio)
|
||||
|
||||
img_resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
||||
paste_x = (target_size[0] - new_width) // 2
|
||||
paste_y = (target_size[1] - new_height) // 2
|
||||
|
||||
shadow_offset = 8
|
||||
shadow_rect = [
|
||||
paste_x + shadow_offset,
|
||||
paste_y + shadow_offset,
|
||||
paste_x + new_width + shadow_offset,
|
||||
paste_y + new_height + shadow_offset
|
||||
]
|
||||
shadow_layer = Image.new('RGBA', target_size, (0, 0, 0, 0))
|
||||
shadow_draw = ImageDraw.Draw(shadow_layer)
|
||||
shadow_draw.rectangle(shadow_rect, fill=(0, 0, 0, 60))
|
||||
shadow_blurred = shadow_layer.filter(ImageFilter.GaussianBlur(radius=10))
|
||||
|
||||
final_image = Image.new('RGB', target_size, border_color)
|
||||
|
||||
if shadow_blurred.mode == 'RGBA':
|
||||
final_image.paste(shadow_blurred, (0, 0), shadow_blurred)
|
||||
else:
|
||||
final_rgb_shadow = shadow_blurred.convert('RGB')
|
||||
final_image.paste(final_rgb_shadow, (0, 0))
|
||||
|
||||
final_image.paste(img_resized, (paste_x, paste_y))
|
||||
|
||||
draw = ImageDraw.Draw(final_image)
|
||||
rect = [paste_x - 2, paste_y - 2, paste_x + new_width + 2, paste_y + new_height + 2]
|
||||
for i in range(3):
|
||||
offset = i + 1
|
||||
current_rect = [
|
||||
rect[0] - offset,
|
||||
rect[1] - offset,
|
||||
rect[2] + offset,
|
||||
rect[3] + offset
|
||||
]
|
||||
draw.rectangle(current_rect, outline=(180, 200, 220))
|
||||
|
||||
for i in range(border_width):
|
||||
current_rect = [
|
||||
rect[0] - i - 3,
|
||||
rect[1] - i - 3,
|
||||
rect[2] + i + 3,
|
||||
rect[3] + i + 3
|
||||
]
|
||||
color_with_alpha = (200 + i*2, 210 + i*2, 230 + i*2)
|
||||
draw.rectangle(current_rect, outline=color_with_alpha)
|
||||
|
||||
final_image.save(output_path, quality=95)
|
||||
print(f'[OK] Processed: {os.path.basename(input_path)} -> {output_path}')
|
||||
return True
|
||||
|
||||
def main():
|
||||
input_files = [
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\1.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\2.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\3.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\4.jpg',
|
||||
r'e:\project\flutter\f\mom_kitchen\docs\design\5.jpg',
|
||||
]
|
||||
|
||||
output_dir = r'e:\project\flutter\f\mom_kitchen\docs\design\processed\portrait'
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
print('='*50)
|
||||
print('Image Border Processing Script (Portrait Mode)')
|
||||
print(f'Target Size: 1080 x 1920 px (Vertical)')
|
||||
print(f'Processing: {len(input_files)} images')
|
||||
print('='*50)
|
||||
print()
|
||||
|
||||
success_count = 0
|
||||
for input_file in input_files:
|
||||
if os.path.exists(input_file):
|
||||
filename = os.path.basename(input_file)
|
||||
output_path = os.path.join(output_dir, f'bordered_portrait_{filename}')
|
||||
try:
|
||||
add_border_and_resize(input_file, output_path)
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
print(f'[ERROR] Failed to process: {filename} - {str(e)}')
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
else:
|
||||
print(f'[WARNING] File not found: {input_file}')
|
||||
|
||||
print()
|
||||
print('='*50)
|
||||
print(f'[DONE] Processed {success_count}/{len(input_files)} images successfully!')
|
||||
print(f'Output directory: {output_dir}')
|
||||
print('='*50)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
65
scripts/package_windows.ps1
Normal file
65
scripts/package_windows.ps1
Normal file
@@ -0,0 +1,65 @@
|
||||
# ============================================================================
|
||||
# 小妈厨房 - Windows 打包脚本
|
||||
# ============================================================================
|
||||
# 使用方法:
|
||||
# .\scripts\package_windows.ps1 # 完整流程:构建+打包
|
||||
# .\scripts\package_windows.ps1 -SkipBuild # 跳过构建,仅打包
|
||||
#
|
||||
# 版本号自动从 pubspec.yaml 读取,无需手动同步
|
||||
# ============================================================================
|
||||
|
||||
param(
|
||||
[switch]$SkipBuild = $false
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||
Set-Location $ProjectRoot
|
||||
|
||||
# ---- 从 pubspec.yaml 读取版本号 ----
|
||||
$pubspec = Get-Content "pubspec.yaml" -Raw
|
||||
if ($pubspec -match "version:\s*(\d+\.\d+\.\d+)(?:\+(\d+))?") {
|
||||
$AppVersion = $Matches[1]
|
||||
$BuildNumber = if ($Matches[2]) { $Matches[2] } else { "0" }
|
||||
Write-Host "Version: $AppVersion (build $BuildNumber)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "ERROR: Cannot parse version from pubspec.yaml" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ---- 构建 Flutter Windows 应用 ----
|
||||
if (-not $SkipBuild) {
|
||||
Write-Host "`n--- Building Flutter Windows app ---" -ForegroundColor Yellow
|
||||
flutter build windows
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "ERROR: Flutter build failed" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Build successful" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "`n--- Skipping build (use -SkipBuild flag) ---" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ---- Inno Setup 打包(通过 /D 传递版本号) ----
|
||||
Write-Host "`n--- Packaging with Inno Setup ---" -ForegroundColor Yellow
|
||||
$isccPath = "d:\Program Files (x86)\Inno Setup 6\ISCC.exe"
|
||||
if (-not (Test-Path $isccPath)) {
|
||||
Write-Host "ERROR: ISCC.exe not found at $isccPath" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
& $isccPath "/DAppVer=$AppVersion" "installer.iss"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "ERROR: Inno Setup packaging failed" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "`n========================================" -ForegroundColor Green
|
||||
Write-Host " Package created successfully!" -ForegroundColor Green
|
||||
Write-Host " Version: $AppVersion" -ForegroundColor Green
|
||||
$outputFile = "dist\MomKitchen_Setup_$AppVersion.exe"
|
||||
if (Test-Path $outputFile) {
|
||||
$size = (Get-Item $outputFile).Length / 1MB
|
||||
Write-Host " Output: $outputFile ($([math]::Round($size, 1)) MB)" -ForegroundColor Green
|
||||
}
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Reference in New Issue
Block a user