Compare commits

...

9 Commits

25 changed files with 1728 additions and 438 deletions

View File

@@ -40,3 +40,9 @@ npm run dev
```sh
npm run build
```
### How to Upload to server
```sh
scp -r dist/ dekthai:/srv/www/html/dekthai/
```

12
docker-compose.yml Normal file
View File

@@ -0,0 +1,12 @@
version: '3.8'
services:
photobooth:
image: nginx:alpine
container_name: photobooth
volumes:
- ./dist:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- '8080:80'
restart: unless-stopped

51
nginx.conf Normal file
View File

@@ -0,0 +1,51 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/xml+rss
application/json;
# Handle static assets with caching
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# Handle service worker
location /sw.js {
add_header Cache-Control "no-cache";
try_files $uri =404;
}
# Handle manifest
location /manifest.webmanifest {
add_header Content-Type "application/manifest+json";
try_files $uri =404;
}
# Handle all other routes - fallback to index.html for SPA routing
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}

BIN
public/assets/bg_home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

BIN
public/assets/bg_home_x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
public/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

BIN
public/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 15 KiB

BIN
public/icon-192x192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -1,4 +0,0 @@
<svg width="192" height="192" xmlns="http://www.w3.org/2000/svg">
<rect width="192" height="192" fill="#667eea" rx="24"/>
<text x="96" y="120" font-family="Arial" font-size="72" fill="white" text-anchor="middle">📷</text>
</svg>

Before

Width:  |  Height:  |  Size: 234 B

BIN
public/icon-512x512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -17,7 +17,7 @@ import HelloWorld from './components/HelloWorld.vue'
</div>
</header> -->
<RouterLink to="/">Home</RouterLink>
<!-- <RouterLink to="/">Home</RouterLink> -->
<RouterView />
</template>

View File

@@ -39,6 +39,11 @@ const router = createRouter({
name: 'pickup',
component: () => import('../views/PickupView.vue'),
},
{
path: '/download',
name: 'download',
component: () => import('../views/DownloadView.vue'),
},
],
})

310
src/views/DownloadView.vue Normal file
View File

@@ -0,0 +1,310 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const imageParam = ref('')
const hasError = ref(false)
const isDownloading = ref(false)
const downloadSuccess = ref(false)
const imageUrl = computed(() => {
if (imageParam.value) {
return `https://assets.dekthai-online.com/static/photobooth/${imageParam.value}`
}
return ''
})
const downloadImage = async () => {
if (!imageUrl.value || isDownloading.value) return
isDownloading.value = true
downloadSuccess.value = false
try {
// Create a temporary link element for download
const link = document.createElement('a')
link.href = imageUrl.value
link.download = imageParam.value || 'photobooth-image.jpg'
link.style.display = 'none'
// Add to DOM, click, and remove
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
// Show success message
downloadSuccess.value = true
// Hide success message after 3 seconds
setTimeout(() => {
downloadSuccess.value = false
}, 3000)
} catch (error) {
console.error('Download failed:', error)
hasError.value = true
} finally {
isDownloading.value = false
}
}
const startOver = () => {
// เคลียร์ข้อมูลและกลับไปหน้าแรก
localStorage.removeItem('photobooth-photos')
localStorage.removeItem('photobooth-layout')
localStorage.removeItem('photobooth-frame')
localStorage.removeItem('photobooth-uploaded-filename')
router.push('/')
}
onMounted(() => {
// Get image parameter from URL query
const image = route.query.image as string
if (image) {
imageParam.value = image
} else {
hasError.value = true
}
})
</script>
<template>
<div class="download-container">
<header class="header">
<h1>ดาวนโหลดรปภาพ</h1>
<p>ปภาพของคณพรอมใหดาวนโหลด</p>
</header>
<section v-if="!hasError && imageUrl" class="download-section">
<div class="download-actions">
<button @click="downloadImage" :disabled="isDownloading" class="start-over-button">
<span v-if="isDownloading" class="button-icon"></span>
<span v-else class="button-icon">📥</span>
{{ isDownloading ? 'กำลังดาวน์โหลด...' : 'ดาวน์โหลดรูปภาพ' }}
</button>
&emsp;
<button @click="startOver" class="start-over-button">
เรมใหม
</button>
<div v-if="downloadSuccess" class="success-message">
ดาวน์โหลดสำเร็จ! ไฟล์ได้บันทึกในเครื่องของคุณแล้ว
</div>
</div>
<div class="additional-actions">
</div>
<div class="image-display">
<img :src="imageUrl" alt="Photo for download" class="download-image" @error="hasError = true" />
</div>
</section>
<section v-else class="error-section">
<div class="error-message">
<h2>ไมพบรปภาพ</h2>
<p>ไมสามารถโหลดรปภาพได กรณาตรวจสอบลงกกคร</p>
</div>
</section>
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.download-container {
min-height: 100vh;
padding: 1.5rem;
background: #fdfaf6;
color: #3e2723;
font-family: 'Old Standard TT', serif;
display: flex;
flex-direction: column;
align-items: center;
}
.header {
text-align: center;
margin-bottom: 2.5rem;
}
.header h1 {
font-size: 2.5rem;
color: #5d4037;
margin-bottom: 0.5rem;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.header p {
color: #6d4c41;
font-size: 1.1rem;
}
.download-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
}
.image-display {
background: #e0d8cf;
padding: 15px;
border-radius: 8px;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
border: 4px solid #a1887f;
}
.download-image {
max-width: 100%;
height: auto;
border-radius: 4px;
display: block;
filter: sepia(0.1) brightness(0.95);
max-height: 70vh;
}
.download-actions {
text-align: center;
}
.download-button {
background: #8d6e63;
color: #fdfaf6;
border: 2px solid #795548;
padding: 1rem 2.5rem;
font-size: 1.2rem;
font-weight: bold;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 0.75rem;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
font-family: 'Crete Round', serif;
text-transform: uppercase;
letter-spacing: 1px;
}
.download-button:hover {
background: #795548;
transform: translateY(-2px);
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.button-icon {
font-size: 1.5rem;
}
.error-section {
text-align: center;
background: #e0d8cf;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
border: 2px solid #bcaaa4;
max-width: 500px;
}
.error-message h2 {
color: #d32f2f;
font-size: 2rem;
margin-bottom: 1rem;
font-family: 'Crete Round', serif;
}
.error-message p {
color: #6d4c41;
font-size: 1.1rem;
}
.download-button:disabled {
opacity: 0.7;
cursor: not-allowed;
transform: none;
}
.download-button:disabled:hover {
transform: none;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.success-message {
margin-top: 1rem;
padding: 1rem;
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
border-radius: 8px;
text-align: center;
font-weight: bold;
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.download-actions {
text-align: center;
}
.additional-actions {
margin-top: 2rem;
text-align: center;
}
.start-over-button {
background: #6d4c41;
color: #fdfaf6;
border: 1px solid #5d4037;
padding: 0.8rem 1.8rem;
font-size: 1rem;
font-weight: bold;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
font-family: 'Old Standard TT', serif;
}
.start-over-button:hover {
background: #5d4037;
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
@media (max-width: 768px) {
.download-image {
max-height: 50vh;
}
.download-button {
width: 280px;
justify-content: center;
font-size: 1.1rem;
padding: 0.8rem 1.5rem;
}
.button-icon {
font-size: 1.3rem;
}
.header h1 {
font-size: 2rem;
}
.error-message h2 {
font-size: 1.5rem;
}
}
</style>

View File

@@ -5,6 +5,7 @@ import { useRouter } from 'vue-router'
const router = useRouter()
const selectedLayout = ref<'1x4' | '2x2'>('1x4')
const selectedFrame = ref<number>(0)
const selectedFilter = ref<'normal' | 'black&white'>('normal')
const layouts = [
{ id: '1x4', name: '1x4 แนวตั้ง', cols: 1, rows: 4 },
@@ -19,6 +20,11 @@ const frames = [
{ id: 4, name: 'กรอบมินิมอล', preview: '/frame-minimal.svg' }
]
const filters = [
{ id: 'normal', name: '🎨Color' },
{ id: 'black&white', name: '🐈⬛Black & White' }
]
const selectLayout = (layoutId: string) => {
selectedLayout.value = layoutId as '1x4' | '2x2'
}
@@ -27,11 +33,17 @@ const selectFrame = (frameId: number) => {
selectedFrame.value = frameId
}
const selectFilter = (filterId: string) => {
selectedFilter.value = filterId as 'normal' | 'black&white'
}
const proceedToSource = () => {
// เก็บข้อมูล layout และ frame ที่เลือกไว้ใน localStorage หรือ state management
localStorage.setItem('photobooth-layout', selectedLayout.value)
localStorage.setItem('photobooth-frame', selectedFrame.value.toString())
localStorage.setItem('photobooth-filter', selectedFilter.value)
router.push('/selectsource')
}
@@ -42,10 +54,11 @@ const goBack = () => {
<template>
<div class="frame-container">
<header class="header">
<!-- <header class="header">
<button @click="goBack" class="back-button"> กล</button>
<h1>เลอกกรอบร</h1>
</header>
</header> -->
<section class="layout-section">
<h2>เลอกรปแบบ</h2>
@@ -69,6 +82,38 @@ const goBack = () => {
</div>
</section>
<section class="filter-section">
<!-- <h2>เลอกฟลเตอร</h2> -->
<div class="filter-options">
<div
v-for="filter in filters"
:key="filter.id"
:class="['filter-option', { selected: selectedFilter === filter.id }]"
@click="selectFilter(filter.id)"
>
<span>{{ filter.name }}</span>
</div>
</div>
</section>
<section class="action-section">
<button @click="proceedToSource" class="next-button">
ดไป
</button>
</section>
<section class="frame-section" style="display: none;">
<h2>เลอกกรอบ</h2>
<div class="frame-options">
@@ -86,19 +131,19 @@ const goBack = () => {
</div>
</section>
<section class="action-section">
<button @click="proceedToSource" class="next-button">
ดไป
</button>
</section>
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.frame-container {
min-height: 100vh;
padding: 2rem;
background: #f8f9fa;
padding: 1.5rem; /* Adjusted padding */
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
}
.header {
@@ -106,53 +151,76 @@ const goBack = () => {
align-items: center;
gap: 1rem;
margin-bottom: 2rem;
background: #e0d8cf; /* Lighter vintage tone for header background */
padding: 1rem 1.5rem;
border-bottom: 1px solid #bcaaa4;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
border-radius: 8px; /* Slightly rounded corners */
}
.back-button {
background: #6c757d;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 8px;
background: #a1887f; /* Vintage brown */
color: #fdfaf6; /* Light text */
border: 1px solid #8d6e63; /* Darker border */
padding: 0.4rem 0.8rem;
border-radius: 5px; /* Softer border-radius */
cursor: pointer;
font-size: 1rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
transition: background 0.2s ease, transform 0.2s ease;
}
.back-button:hover {
background: #8d6e63;
transform: translateY(-1px);
}
.header h1 {
margin: 0;
color: #333;
color: #5d4037; /* Darker brown for title */
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.layout-section, .frame-section {
.layout-section, .frame-section, .filter-section {
margin-bottom: 2rem;
}
h2 {
color: #333;
color: #5d4037; /* Darker brown for subtitle */
margin-bottom: 1rem;
font-size: 1.5rem;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.layout-options, .frame-options {
.layout-options, .frame-options, .filter-options {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
gap: 1rem; /* Increased gap slightly */
margin-bottom: 1rem;
}
.layout-option, .frame-option {
background: white;
border: 2px solid #e9ecef;
border-radius: 12px;
.layout-option, .frame-option, .filter-option {
background: #fdfaf6; /* Vintage paper background */
border: 2px solid #bcaaa4; /* Muted border */
border-radius: 5px; /* Softer border-radius */
padding: 1rem;
cursor: pointer;
transition: all 0.3s ease;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}
.layout-option.selected, .frame-option.selected {
border-color: #007bff;
box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
.layout-option:hover, .frame-option:hover, .filter-option:hover {
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.layout-option.selected, .frame-option.selected, .filter-option.selected {
border-color: #5d4037; /* Darker brown for selection */
box-shadow: 0 0 0 3px rgba(93, 64, 55, 0.2);
}
.layout-preview {
@@ -162,17 +230,18 @@ h2 {
.layout-grid {
display: grid;
gap: 2px;
background: #f8f9fa;
padding: 8px;
border-radius: 8px;
background: #e0d8cf; /* Lighter vintage tone */
padding: 6px; /* Reduced padding */
border-radius: 4px;
aspect-ratio: 3/4;
max-width: 120px;
max-width: 100px;
margin: 0 auto;
border: 1px dashed #bcaaa4; /* Dashed border for a sketched look */
}
.grid-cell {
background: #dee2e6;
border-radius: 4px;
background: #c7b8a7; /* Muted vintage gray/brown */
border-radius: 2px;
}
.frame-preview {
@@ -184,6 +253,8 @@ h2 {
height: 120px;
object-fit: cover;
border-radius: 8px;
border: 1px solid #bcaaa4; /* Subtle border for images */
box-shadow: inset 0 0 5px rgba(0,0,0,0.1); /* Inner shadow for depth */
}
.action-section {
@@ -192,27 +263,40 @@ h2 {
}
.next-button {
background: #28a745;
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.2rem;
background: #8d6e63; /* Vintage brown button */
color: #fdfaf6; /* Light text */
border: 2px solid #795548; /* Darker border for button */
padding: 1rem 2.5rem;
font-size: 1.3rem; /* Slightly larger font */
font-weight: bold;
border-radius: 50px;
border-radius: 8px; /* Softer border-radius */
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(40,167,69,0.3);
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
font-family: 'Crete Round', serif; /* Vintage font for button */
text-transform: uppercase; /* Uppercase text */
letter-spacing: 1px; /* Spaced out letters */
}
.next-button:hover {
background: #218838;
background: #795548; /* Darker brown on hover */
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(40,167,69,0.4);
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
@media (max-width: 768px) {
.layout-options, .frame-options {
.layout-options, .frame-options, .filter-options {
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
h1 {
font-size: 1.8rem; /* Adjust heading size for smaller screens */
}
h2 {
font-size: 1.3rem;
}
.next-button {
font-size: 1.1rem;
padding: 0.8rem 2rem;
}
}
</style>

View File

@@ -1,3 +1,7 @@
<style>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
</style>
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
@@ -20,24 +24,23 @@ const examplePhotos = ref([
<template>
<div class="home-container">
<header class="hero-section">
<h1 class="title">DekThai Photobooth</h1>
<p class="subtitle">สรางรปถายสดพเศษกบกรอบสวยงาม</p>
<img src="/assets/bg_home.png" alt="DekThai Photobooth" style="max-width: 100%;" @click="startPhotobooth"/>
</header>
<section class="examples-section">
<h2>วอยางผลงาน</h2>
<section class="cta-section">
<button @click="startPhotobooth" class="start-button">
<span class="camera-icon">📸</span> เรมสรางรปถาย
</button>
</section>
<section class="examples-section" style="margin-top: 1rem; display: none;">
<!-- <h2>วอยางผลงาน</h2> -->
<div class="photo-examples">
<div class="example-strip">
<img v-for="photo in examplePhotos" :key="photo" :src="photo" alt="Example photo" class="example-photo" />
</div>
</div>
</section>
<section class="cta-section">
<button @click="startPhotobooth" class="start-button">
เรมสรางรปถาย
</button>
</section>
</div>
</template>
@@ -47,31 +50,55 @@ const examplePhotos = ref([
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.5rem;
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
}
.hero-section {
text-align: center;
margin-bottom: 3rem;
background: none; /* Remove background for image */
padding: 0;
border-radius: 0;
box-shadow: none;
}
.hero-section img {
cursor: pointer;
}
.hero-image {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
border-radius: 6px; /* Optional: add some rounded corners to the image */
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
}
.title {
font-size: 3rem;
/* Remove or adjust if not needed, as it's replaced by an image */
font-family: 'Crete Round', serif;
font-size: 3.5rem;
font-weight: bold;
margin-bottom: 1rem;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
text-shadow: 2px 2px 5px rgba(0,0,0,0.2);
color: #5d4037; /* Darker brown for title */
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
/* Remove or adjust if not needed, as it's replaced by an image */
font-size: 1.4rem;
opacity: 0.8;
color: #6d4c41;
}
.examples-section {
margin-bottom: 3rem;
text-align: center;
color: #3e2723;
}
.photo-examples {
@@ -80,50 +107,79 @@ const examplePhotos = ref([
.example-strip {
display: flex;
gap: 1rem;
gap: 1.5rem;
justify-content: center;
flex-wrap: wrap;
}
.example-photo {
width: 120px;
height: 160px;
width: 150px;
height: 200px;
object-fit: cover;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
border-radius: 5px;
box-shadow: 0 3px 10px rgba(0,0,0,0.15);
border: 3px solid #bcaaa4; /* Muted border */
}
.cta-section {
margin-top: 2rem;
margin-top: 0rem;
}
.start-button {
background: #ff6b6b;
color: white;
background: #8d6e63; /* Vintage brown button */
color: #fdfaf6;
border: none;
padding: 1rem 2rem;
font-size: 1.2rem;
padding: 1.2rem 2.5rem;
font-size: 1.5rem;
font-weight: bold;
border-radius: 50px;
border-radius: 15px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(255,107,107,0.4);
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
text-transform: uppercase;
letter-spacing: 1px;
display: flex;
align-items: center;
}
.start-button:hover {
background: #ff5252;
background: #795548;
margin-right: 0.5rem;
transform: translateY(-1px);
font-size: 1.2rem;
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.camera-icon {
background: #795548;
font-size: 1.8rem; /* Adjust icon size */
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255,107,107,0.6);
line-height: 1; /* Ensure icon aligns well with text */ ;
}
@media (max-width: 768px) {
.title {
font-size: 2rem;
font-size: 2.5rem;
}
.subtitle {
font-size: 1.1rem;
}
.example-photo {
width: 80px;
height: 120px;
width: 100px;
height: 140px;
}
}
</style>

View File

@@ -10,6 +10,20 @@ const cachedImageUrl = ref('')
const isGeneratingImage = ref(false)
const hasError = ref(false)
const qrCodeUrl = computed(() => {
const filename = localStorage.getItem('photobooth-uploaded-filename')
if (filename) {
return `https://api.dekthai-online.com/apu-school/qrcode/photobooth.php?key=${filename}`
}
return ''
})
const downloadPageUrl = computed(() => {
const filename = localStorage.getItem('photobooth-uploaded-filename')
if (filename) {
return `${window.location.origin}/download?image=${filename}`
}
return ''
})
onMounted(() => {
// โหลดข้อมูลจาก localStorage
const savedPhotos = localStorage.getItem('photobooth-photos')
@@ -275,15 +289,40 @@ const startOver = () => {
<p>ดาวนโหลดหรอแชรปถายของค</p>
</header>
<section class="actions-section">
<div class="action-buttons">
<button @click="downloadImage" class="download-button">
<span class="button-icon">📥</span>
ดาวนโหลด
</button>
<button @click="startOver" class="start-over-button">
เรมใหม
</button>
</div>
<!-- QR Code สำหร download ปถาย -->
<div v-if="qrCodeUrl" class="qr-code-section">
<h3>สแกน QR Code เพอดาวนโหลด</h3>
<a :href="downloadPageUrl" target="_blank" class="qr-code-link">
<img :src="qrCodeUrl" alt="QR Code for downloading photo" class="qr-code-image" />
</a>
<p class="qr-hint">หร <a :href="downloadPageUrl" target="_blank" class="download-link">คลกท</a> เพอเปดในแทบใหม</p>
</div>
</section>
<section class="result-section">
<div class="photo-result">
<div class="photo-frame" :class="`frame-${frame}`">
<div class="photo-frame"> <!-- Removed dynamic class for frame, styling applied directly -->
<div v-if="isGeneratingImage && !cachedImageUrl" class="loading-indicator">
<div class="spinner"></div>
<p>กำลงสรางภาพ...</p>
</div>
<img v-else-if="cachedImageUrl" :src="cachedImageUrl" alt="Combined Photo" class="combined-image" />
<div v-else-if="hasError" class="error-message">
<p>ไมสามารถสรางภาพได</p>
</div>
@@ -291,28 +330,23 @@ const startOver = () => {
</div>
</section>
<section class="actions-section">
<div class="action-buttons">
<button @click="downloadImage" class="download-button">
<span class="button-icon">📥</span>
ดาวนโหลด
</button>
</div>
</section>
<section class="footer-section">
<button @click="startOver" class="start-over-button">
สรางรปใหม
</button>
</section>
<!-- <section class="footer-section">
</section> -->
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.pickup-container {
min-height: 100vh;
padding: 2rem;
background: #f8f9fa;
padding: 1.5rem; /* Adjusted padding */
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
display: flex;
flex-direction: column;
align-items: center;
@@ -320,22 +354,24 @@ const startOver = () => {
.header {
text-align: center;
margin-bottom: 2rem;
margin-bottom: 2.5rem; /* Adjusted margin */
}
.header h1 {
font-size: 2.5rem;
color: #333;
color: #5d4037; /* Darker brown for title */
margin-bottom: 0.5rem;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.header p {
color: #666;
color: #6d4c41; /* Muted brown for paragraph */
font-size: 1.1rem;
}
.result-section {
margin-bottom: 2rem;
margin-bottom: 2.5rem; /* Adjusted margin */
}
.photo-result {
@@ -344,37 +380,23 @@ const startOver = () => {
}
.photo-frame {
background: white;
padding: 20px;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
max-width: 400px;
background: #e0d8cf; /* Lighter vintage tone for frame background */
padding: 15px; /* Reduced padding for a tighter frame */
border-radius: 8px; /* Softer border-radius */
box-shadow: 0 5px 20px rgba(0,0,0,0.15); /* Softer shadow */
max-width: 420px; /* Matched canvas width */
width: 100%;
border: 4px solid #a1887f; /* Vintage brown border */
}
.photo-grid {
background: #f8f9fa;
border-radius: 8px;
padding: 12px;
}
.photo-cell {
overflow: hidden;
border-radius: 6px;
}
.photo-cell img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
/* Removed photo-grid and photo-cell, as combined-image takes over */
.combined-image {
width: 100%;
height: auto;
border-radius: 8px;
border-radius: 4px; /* Slightly rounded corners for the photo itself */
display: block;
filter: sepia(0.1) brightness(0.95); /* Subtle sepia and brightness for vintage feel */
}
.loading-indicator {
@@ -383,14 +405,14 @@ const startOver = () => {
align-items: center;
justify-content: center;
padding: 2rem;
color: #666;
color: #6d4c41; /* Muted brown */
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid #007bff;
border: 4px solid #bcaaa4; /* Muted gray/brown */
border-top: 4px solid #8d6e63; /* Vintage brown spinner */
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 1rem;
@@ -406,7 +428,7 @@ const startOver = () => {
align-items: center;
justify-content: center;
padding: 2rem;
color: #dc3545;
color: #d32f2f; /* Darker red for error */
text-align: center;
}
@@ -414,97 +436,130 @@ const startOver = () => {
margin-bottom: 2rem;
}
.qr-code-section {
margin-top: 2rem;
text-align: center;
}
.qr-code-section h3 {
color: #5d4037;
font-size: 1.2rem;
margin-bottom: 1rem;
font-family: 'Crete Round', serif;
}
.qr-code-image {
width: 150px;
height: 150px;
border: 2px solid #a1887f;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
transition: transform 0.2s ease;
}
.qr-code-link:hover .qr-code-image {
transform: scale(1.05);
}
.qr-hint {
margin-top: 1rem;
font-size: 0.9rem;
color: #6d4c41;
}
.download-link {
color: #8d6e63;
text-decoration: underline;
font-weight: bold;
}
.download-link:hover {
color: #795548;
}
.action-buttons {
display: flex;
gap: 1rem;
gap: 1.5rem; /* Increased gap */
justify-content: center;
}
.download-button {
background: #007bff;
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.1rem;
background: #8d6e63; /* Vintage brown button */
color: #fdfaf6;
border: 2px solid #795548; /* Darker border */
padding: 1rem 2.5rem; /* Larger padding */
font-size: 1.2rem; /* Slightly larger font */
font-weight: bold;
border-radius: 50px;
border-radius: 20px; /* Softer border-radius */
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 0.5rem;
box-shadow: 0 4px 15px rgba(0,123,255,0.3);
gap: 0.75rem; /* Larger gap for icon */
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
font-family: 'Crete Round', serif; /* Vintage font */
text-transform: uppercase;
letter-spacing: 1px;
}
.download-button:hover {
background: #0056b3;
background: #795548;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0,123,255,0.4);
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.button-icon {
font-size: 1.2rem;
font-size: 1.5rem; /* Larger icon */
}
.footer-section {
margin-top: 2rem;
margin-top: -20px;
}
.start-over-button {
background: #ff6b6b;
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.1rem;
background: #6d4c41; /* Muted brown */
color: #fdfaf6;
border: 1px solid #5d4037;
padding: 0.8rem 1.8rem; /* Adjusted padding */
font-size: 1rem; /* Slightly smaller font */
font-weight: bold;
border-radius: 50px;
border-radius: 20px; /* Softer border-radius */
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(255,107,107,0.3);
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
font-family: 'Old Standard TT', serif;
}
.start-over-button:hover {
background: #ff5252;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255,107,107,0.4);
}
/* Frame styles */
.frame-1 {
/* Modern frame */
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
}
.frame-2 {
/* Vintage frame */
background: linear-gradient(45deg, #f093fb, #f5576c);
}
.frame-3 {
/* Colorful frame */
background: linear-gradient(45deg, #4facfe, #00f2fe);
}
.frame-4 {
/* Minimal frame */
background: #f8f9fa;
border: 2px solid #dee2e6;
background: #5d4037;
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
@media (max-width: 768px) {
.action-buttons {
flex-direction: column;
align-items: center;
gap: 1rem; /* Smaller gap on mobile */
}
.download-button, .share-button {
width: 200px;
.download-button, .start-over-button {
width: 240px; /* Wider buttons on mobile */
justify-content: center;
font-size: 1.1rem;
padding: 0.8rem 1.5rem;
}
.button-icon {
font-size: 1.3rem;
}
.photo-frame {
max-width: 300px;
max-width: 90%; /* Adjust max-width for smaller screens */
padding: 10px;
}
.header h1 {
font-size: 2rem;
}
}
</style>

View File

@@ -8,6 +8,7 @@ const showResult = ref(false)
const photos = ref<string[]>([])
const layout = ref<'1x4' | '2x2'>('1x4')
const frame = ref<number>(0)
const finalImage = ref<string | null>(null)
onMounted(() => {
// โหลดข้อมูลจาก localStorage
@@ -29,8 +30,57 @@ onMounted(() => {
// เริ่มนับถอยหลัง
startCountdown()
// // Load the final image from localStorage
// finalImage.value = localStorage.getItem('photobooth-final-image');
// // Upload the final image to the server
// if (finalImage.value) {
// uploadFinalImage(finalImage.value);
// }
})
const uploadFinalImage = async (imageDataUrl: string) => {
try {
// Compress the image first to reduce size
console.log('Original image size:', imageDataUrl.length);
const compressedImage = await compressImage(imageDataUrl, 0.8); // 80% quality
console.log('Compressed image size:', compressedImage.length);
// Convert compressed base64 data URL to Blob
const response = await fetch(compressedImage);
const blob = await response.blob();
// Create FormData
const formData = new FormData();
const file = new File([blob], 'photobooth-final.jpg', { type: 'image/jpeg' });
formData.append('profile_image', file, file.name);
// Upload to API
const uploadResponse = await fetch('https://api2.dekthai-online.com/g/upload/photobooth', {
method: 'POST',
body: formData
});
if (uploadResponse.ok) {
const result = await uploadResponse.json();
console.log('Upload successful:', result);
// Save the filename to localStorage
if (result.filename) {
localStorage.setItem('photobooth-uploaded-filename', result.filename);
console.log('Filename saved to localStorage:', result.filename);
}
} else {
console.error('Upload failed:', uploadResponse.status, uploadResponse.statusText);
}
} catch (error) {
console.error('Error uploading image:', error);
}
};
const startCountdown = () => {
const timer = setInterval(() => {
countdown.value--
@@ -40,7 +90,7 @@ const startCountdown = () => {
// หลังจากแสดงผล 3 วินาที ให้ไปหน้า pickup
setTimeout(() => {
// router.push('/pickup')
router.push('/pickup')
}, 3000)
}
}, 1000)
@@ -53,7 +103,7 @@ const getGridStyle = () => {
gridTemplateColumns: '1fr',
gridTemplateRows: 'repeat(4, 1fr)',
gap: '8px',
aspectRatio: '1/5' // ทำให้แต่ละภาพยาวขึ้น (1:2 aspect ratio รวม)
aspectRatio: '1/1' // ทำให้แต่ละภาพยาวขึ้น (1:2 aspect ratio รวม)
}
} else {
return {
@@ -65,6 +115,238 @@ const getGridStyle = () => {
}
}
}
const saveToLocalStorage = (key: string, data: any) => {
try {
localStorage.setItem(key, JSON.stringify(data));
} catch (error) {
console.error('Error saving to localStorage:', error);
}
};
const drawFrameBackground = (context: CanvasRenderingContext2D, width: number, height: number, frameType: number) => {
context.clearRect(0, 0, width, height);
switch (frameType) {
case 0: // Classic frame
context.fillStyle = '#ffffff';
context.fillRect(0, 0, width, height);
break;
case 1: // Modern frame
const gradient1 = context.createLinearGradient(0, 0, width, height);
gradient1.addColorStop(0, '#667eea');
gradient1.addColorStop(1, '#764ba2');
context.fillStyle = gradient1;
context.fillRect(0, 0, width, height);
break;
case 2: // Vintage frame
const gradient2 = context.createLinearGradient(0, 0, width, height);
gradient2.addColorStop(0, '#f093fb');
gradient2.addColorStop(1, '#f5576c');
context.fillStyle = gradient2;
context.fillRect(0, 0, width, height);
break;
case 3: // Colorful frame
const gradient3 = context.createLinearGradient(0, 0, width, height);
gradient3.addColorStop(0, '#4facfe');
gradient3.addColorStop(1, '#00f2fe');
context.fillStyle = gradient3;
context.fillRect(0, 0, width, height);
break;
case 4: // Minimal frame
context.fillStyle = '#f8f9fa';
context.fillRect(0, 0, width, height);
context.strokeStyle = '#dee2e6';
context.lineWidth = 4;
context.strokeRect(0, 0, width, height);
break;
default:
console.warn('Unknown frame type:', frameType);
context.fillStyle = '#ffffff';
context.fillRect(0, 0, width, height);
}
};
const drawHeaderFooterImage = async (context: CanvasRenderingContext2D, imagePath: string, x: number, y: number, width: number, height: number) => {
return new Promise<void>((resolve) => {
const img = new Image()
img.onload = () => {
context.drawImage(img, x, y, width, height)
resolve()
}
img.onerror = () => {
console.warn(`Failed to load header/footer image: ${imagePath}, drawing placeholder`)
// วาด placeholder color แทน
if (imagePath.includes('header-1x4')) {
context.fillStyle = '#007bff' // น้ำเงินสำหรับ 1x4 header
} else if (imagePath.includes('footer-1x4')) {
context.fillStyle = '#dc3545' // แดงสำหรับ 1x4 footer
} else if (imagePath.includes('header-2x2')) {
context.fillStyle = '#28a745' // เขียวสำหรับ 2x2 header
} else if (imagePath.includes('footer-2x2')) {
context.fillStyle = '#ffc107' // เหลืองสำหรับ 2x2 footer
}
context.fillRect(x, y, width, height)
resolve()
}
img.src = imagePath
})
}
const generateAndCacheImage = async () => {
try {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
if (!context) {
throw new Error('Could not get canvas context')
}
// ขนาดรูปแต่ละภาพ (360x480 = 3:4) - ลดขนาดลงเพื่อป้องกันปัญหา canvas ใหญ่เกินไป
const photoWidth = 360
const photoHeight = 480
const gap = 20 // ระยะห่างระหว่างรูป
let canvasWidth, canvasHeight
let headerHeight = 0, footerHeight = 0
let sidePadding = 0
if (layout.value === '1x4') {
// 1x4: 1 คอลัมน์ 4 แถว + header/footer
headerHeight = 50
footerHeight = 50
sidePadding = 30 // padding ซ้ายขวาเพื่อให้ total width = 420
canvasWidth = 420
canvasHeight = headerHeight + (photoHeight * 4) + (gap * 3) + footerHeight
} else {
// 2x2: 2 คอลัมน์ 2 แถว + header/footer
headerHeight = 60
footerHeight = 60
sidePadding = 20 // padding ซ้ายขวาเพื่อให้ total width = 780
canvasWidth = 780
canvasHeight = headerHeight + (photoHeight * 2) + gap + footerHeight
}
console.log('Canvas dimensions:', canvasWidth, 'x', canvasHeight)
canvas.width = canvasWidth
canvas.height = canvasHeight
// วาด background ตาม frame
drawFrameBackground(context, canvasWidth, canvasHeight, frame.value)
// วาด header image
const headerImagePath = layout.value === '1x4' ? '/assets/header-1x4.png' : '/assets/header-2x2.png'
await drawHeaderFooterImage(context, headerImagePath, 0, 0, canvasWidth, headerHeight)
// วาด footer image
const footerImagePath = layout.value === '1x4' ? '/assets/footer-1x4.png' : '/assets/footer-2x2.png'
await drawHeaderFooterImage(context, footerImagePath, 0, canvasHeight - footerHeight, canvasWidth, footerHeight)
// วาดรูปภาพ (มี padding ซ้ายขวา)
for (let i = 0; i < photos.value.length; i++) {
const photoSrc = photos.value[i]
if (!photoSrc) continue
const img = new Image()
img.src = photoSrc
await new Promise((resolve) => {
img.onload = () => {
let x, y
if (layout.value === '1x4') {
// 1x4 layout - วาดรูปตรงกลาง (มี padding ซ้ายขวา)
x = sidePadding
y = headerHeight + i * (photoHeight + gap)
} else {
// 2x2 layout - วาดรูปตรงกลาง (มี padding ซ้ายขวา)
const col = i % 2
const row = Math.floor(i / 2)
x = sidePadding + col * (photoWidth + gap)
y = headerHeight + row * (photoHeight + gap)
}
// วาดรูปภาพ
context.drawImage(img, x, y, photoWidth, photoHeight)
resolve(void 0)
}
img.onerror = () => {
console.error(`Failed to load image ${i}`)
resolve(void 0)
}
})
}
// สร้าง compressed JPEG data URL และบันทึกใน localStorage
const dataUrl = canvas.toDataURL('image/jpeg', 0.8) // 80% quality JPEG
try {
saveToLocalStorage('photobooth-final-image', dataUrl);
finalImage.value = dataUrl;
// Load the final image from localStorage
finalImage.value = localStorage.getItem('photobooth-final-image');
// Upload the final image to the server
if (finalImage.value) {
uploadFinalImage(dataUrl);
}
} catch (error) {
if (error instanceof DOMException && error.name === 'QuotaExceededError') {
console.error('localStorage quota exceeded for cached image')
alert('ไม่สามารถบันทึกภาพได้เนื่องจากพื้นที่เก็บข้อมูลไม่เพียงพอ')
} else {
console.error('Error saving cached image:', error)
throw error
}
}
} catch (error) {
console.error('Error in generateAndCacheImage:', error)
}
}
const compressImage = (dataUrl: string, quality: number): Promise<string> => {
return new Promise((resolve) => {
const img = new Image();
img.src = dataUrl;
img.onload = () => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
if (!ctx) {
console.error('Canvas context not available for compression');
resolve(dataUrl);
return;
}
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
resolve(canvas.toDataURL('image/jpeg', quality));
};
img.onerror = () => {
console.error('Failed to compress image');
resolve(dataUrl);
};
});
};
onMounted(() => {
// ...existing code...
generateAndCacheImage();
});
</script>
<template>
@@ -80,43 +362,45 @@ const getGridStyle = () => {
</div>
</div>
<div v-else class="result-section">
<div class="result-header">
<h1>เสรจแล!</h1>
<p>กำลงเตรยมไฟลสำหรบดาวนโหลด...</p>
</div>
<div class="photo-result">
<div class="photo-frame" :class="`frame-${frame}`">
<div class="photo-grid" :style="getGridStyle()">
<div
v-for="(photo, index) in photos"
:key="index"
class="photo-cell"
>
<img :src="photo" :alt="`Photo ${index + 1}`" />
</div>
</div>
<!-- <div class="final-image-display">
<img v-if="finalImage" :src="finalImage" alt="Final Combined Image" />
</div> -->
<div class="loading-indicator">
<!-- <div class="spinner"></div> -->
<!-- <span>กำลงสรางไฟล...</span> -->
</div>
</div>
<div class="loading-indicator">
<div class="spinner"></div>
<span>กำลงสรางไฟล...</span>
</div>
</div>
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.print-container {
min-height: 100vh;
background: #000;
color: white;
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
padding: 1.5rem; /* Adjusted padding */
}
.countdown-section {
@@ -131,83 +415,80 @@ const getGridStyle = () => {
.countdown-number {
font-size: 8rem;
font-weight: bold;
color: #ff6b6b;
color: #ff5e3a; /* Vintage orange-red for countdown */
margin-bottom: 1rem;
animation: scalePulse 1s ease-in-out infinite;
font-family: 'Crete Round', serif; /* Vintage font for number */
text-shadow: 2px 2px 5px rgba(255, 94, 58, 0.5); /* Subtle glow */
}
.processing-text {
font-size: 1.5rem;
color: #ccc;
color: #6d4c41; /* Muted brown for text */
font-family: 'Crete Round', serif;
}
.progress-bar {
width: 300px;
height: 8px;
background: rgba(255,255,255,0.2);
border-radius: 4px;
height: 10px; /* Slightly thicker progress bar */
background: #e0d8cf; /* Lighter vintage tone */
border-radius: 5px; /* Softer border-radius */
margin: 0 auto;
overflow: hidden;
box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
border-radius: 4px;
background: linear-gradient(90deg, #a1887f, #8d6e63); /* Vintage brown gradient */
border-radius: 5px;
transition: width 1s ease-in-out;
box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
.result-section {
text-align: center;
animation: slideUp 0.8s ease-out;
background: #e0d8cf; /* Lighter vintage background for result section */
padding: 2rem;
border-radius: 12px;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
border: 2px solid #bcaaa4;
}
.result-header h1 {
font-size: 3rem;
margin-bottom: 0.5rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
background: linear-gradient(45deg, #5d4037, #8d6e63); /* Darker vintage brown gradient */
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.result-header p {
font-size: 1.2rem;
color: #ccc;
margin-bottom: 2rem;
color: #6d4c41; /* Muted brown */
margin-bottom: 1.5rem; /* Adjusted margin */
}
.photo-result {
margin: 2rem 0;
display: flex;
justify-content: center;
}
.photo-frame {
background: white;
padding: 20px;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(255,255,255,0.1);
max-width: 400px;
width: 100%;
}
.photo-grid {
background: #f8f9fa;
.final-image-display {
margin-top: 2rem;
display: inline-block; /* Allows auto width */
border: 4px solid #a1887f; /* Vintage frame border */
border-radius: 8px;
padding: 12px;
padding: 8px; /* Inner padding for the frame */
background: #fdfaf6; /* Background inside the frame */
box-shadow: 0 8px 25px rgba(0,0,0,0.2); /* Deeper shadow for the whole frame */
}
.photo-cell {
overflow: hidden;
border-radius: 6px;
}
.photo-cell img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
.final-image-display img {
max-width: 100%;
height: auto;
display: block; /* Remove extra space below image */
border-radius: 4px; /* Slightly rounded corners for the photo itself */
filter: sepia(0.1) brightness(0.95); /* Subtle vintage photo effect */
}
.loading-indicator {
@@ -221,14 +502,14 @@ const getGridStyle = () => {
.spinner {
width: 24px;
height: 24px;
border: 3px solid rgba(255,255,255,0.3);
border-top: 3px solid #ff6b6b;
border: 3px solid rgba(177,162,152,0.5); /* Muted gray/brown */
border-top: 3px solid #8d6e63; /* Vintage brown spinner */
border-radius: 50%;
animation: spin 1s linear infinite;
}
.loading-indicator span {
color: #ccc;
color: #6d4c41; /* Muted brown */
font-size: 1.1rem;
}
@@ -258,33 +539,6 @@ const getGridStyle = () => {
100% { transform: rotate(360deg); }
}
/* Frame styles */
.frame-0 {
/* Classic frame - default white */
}
.frame-1 {
/* Modern frame */
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
}
.frame-2 {
/* Vintage frame */
background: linear-gradient(45deg, #f093fb, #f5576c);
}
.frame-3 {
/* Colorful frame */
background: linear-gradient(45deg, #4facfe, #00f2fe);
}
.frame-4 {
/* Minimal frame */
background: #f8f9fa;
border: 2px solid #dee2e6;
}
@media (max-width: 768px) {
.countdown-number {
font-size: 6rem;
@@ -294,8 +548,9 @@ const getGridStyle = () => {
font-size: 2rem;
}
.photo-frame {
max-width: 300px;
.final-image-display {
padding: 6px;
border-width: 3px;
}
}
</style>

View File

@@ -14,42 +14,64 @@ const goToUpload = () => {
const goBack = () => {
router.push('/frame')
}
const goToHome = () => {
router.push('/frame')
}
</script>
<template>
<div class="source-container">
<header class="header">
<!-- <header class="header">
<button @click="goBack" class="back-button"> กล</button>
<h1>เลอกแหลงภาพ</h1>
</header>
</header> -->
<section class="options-section">
<div class="option-card" @click="goToShooting">
<div class="option-icon">
📷
</div>
<h3>ายภาพใหม</h3>
<p>ายภาพ 4 ปจากกลองหรอเวบแคม</p>
<div class="arrow"></div>
<!-- <h3>ายภาพใหม</h3> -->
<p>ายภาพจากกลองหรอเวบแคม</p>
<!-- <div class="arrow"></div> -->
</div>
<div class="option-card" @click="goToUpload">
<div class="option-icon">
🖼
</div>
<h3>พโหลดภาพ</h3>
<p>เลอกภาพ 4 จากคลงภาพในอปกรณ</p>
<div class="arrow"></div>
<!-- <h3>พโหลดภาพ</h3> -->
<p>เลอกภาพจากคลงภาพในอปกรณ</p>
<!-- <div class="arrow"></div> -->
</div>
</section>
<section class="options-fillter">
<!-- switch filter black&white -->
</section>
<footer class="footer-actions">
<button @click="goToHome" class="start-button">กลบหนาแรก</button>
</footer>
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.source-container {
min-height: 100vh;
padding: 2rem;
background: #f8f9fa;
padding: 1.5rem; /* Adjusted padding */
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
display: flex;
flex-direction: column;
}
@@ -58,87 +80,138 @@ const goBack = () => {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 3rem;
margin-bottom: 2.5rem; /* Adjusted margin */
background: #e0d8cf; /* Lighter vintage tone for header background */
padding: 1rem 1.5rem;
border-bottom: 1px solid #bcaaa4;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
border-radius: 8px; /* Slightly rounded corners */
}
.back-button {
background: #6c757d;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 8px;
background: #a1887f; /* Vintage brown */
color: #fdfaf6; /* Light text */
border: 1px solid #8d6e63; /* Darker border */
padding: 0.4rem 0.8rem;
border-radius: 5px; /* Softer border-radius */
cursor: pointer;
font-size: 1rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
transition: background 0.2s ease, transform 0.2s ease;
}
.back-button:hover {
background: #8d6e63;
transform: translateY(-1px);
}
.header h1 {
margin: 0;
color: #333;
color: #5d4037; /* Darker brown for title */
font-family: 'Crete Round', serif;
font-size: 2rem;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.options-section {
display: flex;
flex-direction: column;
gap: 2rem;
gap: 1.5rem; /* Adjusted gap */
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.option-card {
background: white;
border-radius: 16px;
padding: 2rem;
background: #fdfaf6; /* Vintage paper background */
border-radius: 8px; /* Softer border-radius */
padding: 1.5rem; /* Adjusted padding */
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
box-shadow: 0 3px 8px rgba(0,0,0,0.1); /* Softer shadow */
display: flex;
align-items: center;
gap: 1.5rem;
position: relative;
border: 2px solid #bcaaa4; /* Muted border */
}
.option-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
transform: translateY(-2px);
box-shadow: 0 5px 12px rgba(0,0,0,0.15);
}
.option-icon {
font-size: 3rem;
width: 80px;
height: 80px;
font-size: 2.5rem; /* Slightly smaller icon */
width: 70px; /* Adjusted size */
height: 70px; /* Adjusted size */
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
background: #a1887f; /* Vintage brown color */
border-radius: 50%;
color: white;
color: #fdfaf6; /* Light text color */
box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); /* Inner shadow for depth */
}
.start-button {
background: #8d6e63; /* Vintage brown button */
margin-top: 2rem;
color: #fdfaf6;
border: none;
padding: 1.2rem 2.5rem;
font-size: 1.1rem;
font-weight: bold;
border-radius: 15px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
text-transform: uppercase;
letter-spacing: 1px;
display: flex;
align-items: center;
}
.start-button:hover {
background: #795548;
margin-right: 0.5rem;
transform: translateY(-1px);
font-size: 1.2rem;
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.option-card h3 {
margin: 0 0 0.5rem 0;
color: #333;
font-size: 1.5rem;
color: #5d4037; /* Darker brown for heading */
font-size: 1.4rem; /* Slightly smaller heading */
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.05);
}
.option-card p {
margin: 0;
color: #666;
color: #6d4c41; /* Muted brown for paragraph */
flex: 1;
font-size: 0.95rem; /* Slightly smaller paragraph font */
}
.arrow {
font-size: 1.5rem;
color: #007bff;
color: #8d6e63; /* Vintage brown for arrow */
font-weight: bold;
}
@media (max-width: 768px) {
.footer-actions {
display: flex;
justify-content: center;
margin-top: 2rem;
}
.option-card {
flex-direction: column;
text-align: center;
gap: 1rem;
padding: 1.2rem;
}
.option-icon {
@@ -146,5 +219,8 @@ const goBack = () => {
height: 60px;
font-size: 2rem;
}
.header h1 {
font-size: 1.8rem;
}
</style>

View File

@@ -67,9 +67,9 @@ const applyFilmEffect = (context: CanvasRenderingContext2D, width: number, heigh
const grainStrength = volume * 1.5;
for (let i = 0; i < data.length; i += 4) {
let r = data[i];
let g = data[i + 1];
let b = data[i + 2];
let r = data[i]!;
let g = data[i + 1]!;
let b = data[i + 2]!;
// --- STEP 1: Apply Contrast (ทำให้ภาพไม่แบน) ---
// สูตร Contrast มาตรฐาน
@@ -123,6 +123,65 @@ const addVignette = (ctx: CanvasRenderingContext2D, w: number, h: number, streng
ctx.fillRect(0, 0, w, h);
};
const applyBlackAndWhite = (context: CanvasRenderingContext2D, width: number, height: number, volume: number = 5) => {
const imageData = context.getImageData(0, 0, width, height);
const data = imageData.data;
// 1. คำนวณ Contrast ตาม Volume (ยิ่งเยอะ ยิ่งตัดกันเข้ม)
const contrast = (volume / 10) * 80; // ปรับความเข้มข้น (0-80)
const contrastFactor = (259 * (contrast + 255)) / (255 * (259 - contrast));
// 2. ปรับ Brightness (Exposure) ชดเชยเวลา Contrast สูงๆ แล้วภาพมืด
const brightness = volume * 2;
for (let i = 0; i < data.length; i += 4) {
const r = data[i]!;
const g = data[i + 1]!;
const b = data[i + 2]!;
// --- STEP 1: Grayscale Conversion (สูตร Portrait) ---
// ปกติ: r*0.3, g*0.59, b*0.11
// สูตรนี้: เพิ่มน้ำหนัก Red เป็น 0.4 เพื่อให้ "ผิวคน" ดูสว่างขึ้น (Skin Tone Brightening)
let gray = (r * 0.4) + (g * 0.5) + (b * 0.1);
// --- STEP 2: Apply Contrast & Brightness ---
gray = contrastFactor * (gray - 128) + 128 + brightness;
// --- STEP 3: Clamp Values ---
// บังคับค่าให้อยู่ในช่วง 0-255 และกำหนดให้ทั้ง R, G, B เท่ากัน (เพื่อเป็นสีเทา)
const finalGray = Math.max(0, Math.min(255, gray));
data[i] = finalGray; // R
data[i + 1] = finalGray; // G
data[i + 2] = finalGray; // B
// data[i+3] คือ Alpha ไม่ต้องยุ่ง
}
context.putImageData(imageData, 0, 0);
// --- STEP 4: Noir Effect (แสงฟุ้ง + ขอบมืด) ---
// ถ้าปรับ volume เยอะๆ ให้เติมขอบดำ เพื่อให้ดูเป็นสไตล์ Noir/Classic
if (volume > 3) {
addNoirVignette(context, width, height, volume);
}
};
// ฟังก์ชันสร้างขอบดำสำหรับขาวดำโดยเฉพาะ
const addNoirVignette = (ctx: CanvasRenderingContext2D, w: number, h: number, strength: number) => {
// ความเข้มของขอบดำ
const opacity = (strength / 10) * 0.8; // สูงสุด 0.8 (เข้มกว่าแบบฟิล์ม)
const radius = Math.max(w, h) * 0.7; // วงแคบกว่าฟิล์มหน่อย เพื่อเน้นหน้าคนตรงกลาง
const gradient = ctx.createRadialGradient(w/2, h/2, w/4, w/2, h/2, radius);
gradient.addColorStop(0, "rgba(0,0,0,0)");
gradient.addColorStop(1, `rgba(0,0,0,${opacity})`);
ctx.save();
ctx.globalCompositeOperation = 'multiply'; // ใช้ Multiply ให้เงามันซึมลงไปในภาพ
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, w, h);
ctx.restore();
};
const drawDateStamp = (context: CanvasRenderingContext2D, width: number, height: number) => {
const now = new Date();
@@ -206,11 +265,20 @@ const captureSinglePhoto = () => {
)
// Apply film effect with default volume
applyFilmEffect(context, finalWidth, finalHeight, 5);
drawDateStamp(context, finalWidth, finalHeight);
// applyFilmEffect(context, finalWidth, finalHeight, 2);
const filter = localStorage.getItem('photobooth-filter') || 'normal'
if (filter === 'black&white') {
applyBlackAndWhite(context, finalWidth, finalHeight, 3);
} else {
applyFilmEffect(context, finalWidth, finalHeight, 2); // Default volume = 5
}
// drawDateStamp(context, finalWidth, finalHeight);
// แปลงเป็น base64 ด้วย quality 0.7 เพื่อลดขนาด
const photoDataUrl = canvas.toDataURL('image/jpeg', 0.7)
const photoDataUrl = canvas.toDataURL('image/jpeg', 0.8)
photos.value.push(photoDataUrl)
currentPhotoIndex.value++
@@ -304,11 +372,12 @@ const retakePhoto = () => {
<template>
<div class="shooting-container">
<header class="header">
<!-- <header class="header">
<button @click="goBack" class="back-button"> กล</button>
<h1>ายภาพ</h1>
<span class="photo-counter">{{ currentPhotoIndex }}/{{ totalPhotos }}</span>
</header>
</header> -->
<section class="camera-section">
<div class="camera-container">
@@ -373,11 +442,14 @@ const retakePhoto = () => {
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.shooting-container {
min-height: 100vh;
padding: 2rem;
background: #000;
color: white;
padding: 1.5rem; /* Adjusted padding */
background: #fdfaf6; /* Dark brown, vintage background */
color: #fdfaf6; /* Light vintage paper color for text */
font-family: 'Old Standard TT', serif;
display: flex;
flex-direction: column;
}
@@ -387,28 +459,46 @@ const retakePhoto = () => {
align-items: center;
justify-content: space-between;
margin-bottom: 2rem;
background: #5d4037; /* Darker vintage tone for header */
padding: 0.8rem 1.2rem;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
border: 1px solid #4e342e;
}
.back-button {
background: rgba(255,255,255,0.2);
color: white;
border: 1px solid rgba(255,255,255,0.3);
padding: 0.5rem 1rem;
border-radius: 8px;
background: #8d6e63; /* Vintage brown */
color: #fdfaf6;
border: 1px solid #795548;
padding: 0.4rem 0.8rem;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
transition: background 0.2s ease, transform 0.2s ease;
}
.back-button:hover {
background: #795548;
transform: translateY(-1px);
}
.header h1 {
margin: 0;
font-size: 2rem;
font-family: 'Crete Round', serif;
color: #fdfaf6;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.photo-counter {
background: rgba(255,255,255,0.2);
background: #a1887f; /* Muted brown */
padding: 0.5rem 1rem;
border-radius: 20px;
font-weight: bold;
color: #fdfaf6;
border: 1px solid #8d6e63;
}
.camera-section {
@@ -424,15 +514,18 @@ const retakePhoto = () => {
width: 100%;
max-width: 400px;
aspect-ratio: 3/4;
border-radius: 16px;
border-radius: 12px; /* Slightly softer radius */
overflow: hidden;
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
box-shadow: 0 5px 20px rgba(0,0,0,0.4); /* Darker, more prominent shadow */
border: 4px solid #4e342e; /* Frame-like border */
background: #2b1c18; /* Darker background inside frame */
}
.camera-video {
width: 100%;
height: 100%;
object-fit: cover;
transform: scaleX(-1);
}
.hidden-canvas {
@@ -454,28 +547,30 @@ const retakePhoto = () => {
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
background: rgba(43, 28, 24, 0.85); /* Darker, vintage transparent overlay */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
animation: countdownFade 1s ease-in-out;
animation: none; /* Removed fade animation for countdown */
}
.countdown-info {
font-size: 1.5rem;
font-weight: bold;
color: white;
color: #fdfaf6; /* Light text */
margin-bottom: 1rem;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
font-family: 'Crete Round', serif;
}
.countdown-number {
font-size: 8rem;
font-size: 7rem; /* Slightly smaller number */
font-weight: bold;
color: white;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
color: #ff5e3a; /* Vintage orange-red for countdown */
text-shadow: 2px 2px 5px rgba(255, 94, 58, 0.7); /* Glowing effect */
animation: countdownPulse 1s ease-in-out;
font-family: 'Digital-7', monospace; /* Ideal for digital clock look, otherwise Courier New */
}
.capture-guide {
@@ -489,8 +584,8 @@ const retakePhoto = () => {
.guide-frame {
width: 80%;
height: 80%;
border: 3px solid rgba(255,255,255,0.5);
border-radius: 12px;
border: 2px dashed rgba(253,250,246,0.5); /* Dashed light border for guide */
border-radius: 8px;
}
.controls {
@@ -501,54 +596,72 @@ const retakePhoto = () => {
}
.capture-button {
background: #ff6b6b;
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.2rem;
background: #a1887f; /* Vintage brown */
color: #fdfaf6;
border: 2px solid #8d6e63;
padding: 1rem 2.5rem;
font-size: 1.3rem;
font-weight: bold;
border-radius: 50px;
border-radius: 8px; /* Softer border-radius */
cursor: pointer;
transition: all 0.3s ease;
min-width: 200px;
min-width: 220px;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
font-family: 'Crete Round', serif;
text-transform: uppercase;
letter-spacing: 1px;
}
.capture-button:hover:not(:disabled) {
background: #ff5252;
transform: scale(1.05);
background: #8d6e63;
transform: translateY(-2px);
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
.capture-button:disabled {
opacity: 0.6;
opacity: 0.5;
cursor: not-allowed;
background: #a1887f; /* Keep base color */
border-color: #8d6e63;
box-shadow: none;
}
.capturing {
animation: pulse 0.5s ease-in-out;
animation: pulse 0.5s ease-in-out infinite alternate; /* Keep pulse but make it subtle */
}
.retake-button {
background: rgba(255,255,255,0.2);
color: white;
border: 1px solid rgba(255,255,255,0.3);
padding: 0.75rem 1.5rem;
border-radius: 25px;
background: #6d4c41; /* Muted brown */
color: #fdfaf6;
border: 1px solid #5d4037;
padding: 0.7rem 1.4rem;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: bold;
font-family: 'Old Standard TT', serif;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.retake-button:hover {
background: rgba(255,255,255,0.3);
background: #5d4037;
transform: translateY(-1px);
}
.preview-section {
margin-top: 2rem;
text-align: center;
background: #2b1c18; /* Dark background for preview section */
padding: 1.5rem;
border-radius: 10px;
box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
}
.preview-section h3 {
margin-bottom: 1rem;
color: #ccc;
color: #fdfaf6;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.05);
}
.photo-preview {
@@ -560,53 +673,48 @@ const retakePhoto = () => {
.preview-item {
position: relative;
width: 60px;
width: 70px; /* Slightly larger preview items */
aspect-ratio: 3/4;
border-radius: 8px;
border-radius: 4px; /* Sharper corners for printed photo look */
overflow: hidden;
border: 2px solid #bcaaa4; /* Frame-like border for previews */
box-shadow: 0 2px 5px rgba(0,0,0,0.15); /* Subtle shadow for depth */
}
.preview-item img {
width: 100%;
height: 100%;
object-fit: cover;
filter: sepia(0.1) brightness(0.95); /* Subtle sepia and brightness for vintage feel */
}
.photo-number {
position: absolute;
top: 4px;
right: 4px;
background: rgba(0,0,0,0.7);
color: white;
width: 20px;
height: 20px;
background: #8d6e63; /* Vintage brown for number badge */
color: #fdfaf6;
width: 22px; /* Slightly larger badge */
height: 22px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
@keyframes countdownFade {
0% { opacity: 0; }
10% { opacity: 1; }
90% { opacity: 1; }
100% { opacity: 0; }
0% { transform: scale(1); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
50% { transform: scale(1.02); box-shadow: 0 6px 15px rgba(0,0,0,0.3); }
100% { transform: scale(1); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
}
@keyframes countdownPulse {
0% { transform: scale(0.8); opacity: 0; }
20% { transform: scale(1.2); opacity: 1; }
50% { transform: scale(1); }
80% { transform: scale(1.1); }
100% { transform: scale(1); opacity: 0; }
0% { transform: scale(0.8); opacity: 0.5; }
50% { transform: scale(1.1); opacity: 1; }
100% { transform: scale(1); opacity: 0.8; }
}
@media (max-width: 768px) {
@@ -620,7 +728,23 @@ const retakePhoto = () => {
.preview-item {
width: 60px;
height: 60px;
height: auto; /* Adjust height automatically with aspect-ratio */
}
.header h1 {
font-size: 1.8rem;
}
.countdown-number {
font-size: 5rem;
}
.capture-button {
font-size: 1.1rem;
padding: 0.8rem 2rem;
min-width: 180px;
}
.retake-button {
font-size: 0.9rem;
padding: 0.6rem 1.2rem;
}
}
</style>

View File

@@ -26,9 +26,9 @@ const applyFilmEffect = (context: CanvasRenderingContext2D, width: number, heigh
const grainStrength = volume * 1.5;
for (let i = 0; i < data.length; i += 4) {
let r = data[i];
let g = data[i + 1];
let b = data[i + 2];
let r = data[i]!;
let g = data[i + 1]!;
let b = data[i + 2]!;
// --- STEP 1: Apply Contrast (ทำให้ภาพไม่แบน) ---
// สูตร Contrast มาตรฐาน
@@ -66,7 +66,6 @@ const applyFilmEffect = (context: CanvasRenderingContext2D, width: number, heigh
addVignette(context, width, height, volume);
}
};
// ฟังก์ชันเสริมสำหรับทำขอบมืด (Vignette)
const addVignette = (ctx: CanvasRenderingContext2D, w: number, h: number, strength: number) => {
const opacity = (strength / 10) * 0.6; // สูงสุดที่ 0.6 opacity
@@ -82,6 +81,143 @@ const addVignette = (ctx: CanvasRenderingContext2D, w: number, h: number, streng
ctx.fillRect(0, 0, w, h);
};
const applySelfieFilter = (context: CanvasRenderingContext2D, width: number, height: number, volume: number = 5) => {
const imageData = context.getImageData(0, 0, width, height);
const data = imageData.data;
// แปลง Volume เป็นค่า Config
const brightness = (volume / 10) * 40; // เพิ่มความสว่าง (0 - 40)
const contrast = 1.05 + (volume / 100); // เพิ่ม Contrast นิดเดียวให้ภาพไม่จม (1.05 - 1.15)
// Factor สำหรับลดความเหลือง (Desaturation) ยิ่งเยอะผิวยิ่งดูขาวซีด
const saturationFactor = 1 - (volume / 50); // ลดความสดสีลงนิดหน่อย
const contrastFactor = (259 * (contrast * 255 + 255)) / (255 * (259 - contrast * 255));
for (let i = 0; i < data.length; i += 4) {
let r = data[i]!;
let g = data[i + 1]!;
let b = data[i + 2]!;
// --- STEP 1: Brightness & Contrast ---
// ปรับ Contrast และ Brightness พื้นฐาน
r = contrastFactor * (r - 128) + 128 + brightness;
g = contrastFactor * (g - 128) + 128 + brightness;
b = contrastFactor * (b - 128) + 128 + brightness;
// --- STEP 2: Skin Whitening Logic (Desaturation) ---
// คำนวณค่าสีเทา (Luminance)
const gray = r * 0.3 + g * 0.59 + b * 0.11;
// ผสมสีเดิมเข้ากับสีเทา เพื่อลดความสดของสีผิว (ทำให้ผิวที่เหลือง/คล้ำ ดูขาวขึ้น)
r = r * saturationFactor + gray * (1 - saturationFactor);
g = g * saturationFactor + gray * (1 - saturationFactor);
b = b * saturationFactor + gray * (1 - saturationFactor);
// --- STEP 3: Tone Tuning (อมชมพูระเรื่อ) ---
// เพิ่มสีแดงและฟ้านิดๆ ให้ดูขาวอมชมพู (ไม่เหลือง)
r += volume * 1.5; // เพิ่มแดง
b += volume * 0.5; // เพิ่มฟ้านิดเดียว (Cool tone)
// Clamp values
data[i] = Math.max(0, Math.min(255, r));
data[i + 1] = Math.max(0, Math.min(255, g));
data[i + 2] = Math.max(0, Math.min(255, b));
}
context.putImageData(imageData, 0, 0);
// --- STEP 4: Soft Focus (หน้าเนียน) ---
// ใช้เทคนิค Screen Layer สีขาวจางๆ ทำให้รูขุมขนหายไป หน้าดูฟุ้ง
if (volume > 0) {
addSoftGlow(context, width, height, volume);
}
};
// ฟังก์ชันทำหน้าเนียน (Soft Glow)
const addSoftGlow = (ctx: CanvasRenderingContext2D, w: number, h: number, strength: number) => {
ctx.save();
// ใช้โหมด Screen หรือ Overlay เพื่อให้ความสว่างกลืนไปกับภาพ
ctx.globalCompositeOperation = 'screen';
// สีขาวจางๆ ตามระดับความแรง
const opacity = (strength / 10) * 0.15; // สูงสุด 15% (ถ้าเยอะไปหน้าจะวอก)
ctx.fillStyle = `rgba(255, 255, 255, ${opacity})`;
ctx.fillRect(0, 0, w, h);
// (Optional) เพิ่มสีชมพูจางๆ ตรงกลางแก้ม (Blush Effect)
// ถ้าต้องการให้กดแล้วดูแก้มชมพูด้วย
/*
const gradient = ctx.createRadialGradient(w/2, h/2, w/4, w/2, h/2, w);
gradient.addColorStop(0, `rgba(255, 200, 200, ${opacity * 0.5})`);
gradient.addColorStop(1, "rgba(255, 255, 255, 0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, w, h);
*/
ctx.restore();
};
const applyBlackAndWhite = (context: CanvasRenderingContext2D, width: number, height: number, volume: number = 5) => {
const imageData = context.getImageData(0, 0, width, height);
const data = imageData.data;
// 1. คำนวณ Contrast ตาม Volume (ยิ่งเยอะ ยิ่งตัดกันเข้ม)
const contrast = (volume / 10) * 80; // ปรับความเข้มข้น (0-80)
const contrastFactor = (259 * (contrast + 255)) / (255 * (259 - contrast));
// 2. ปรับ Brightness (Exposure) ชดเชยเวลา Contrast สูงๆ แล้วภาพมืด
const brightness = volume * 2;
for (let i = 0; i < data.length; i += 4) {
const r = data[i]!;
const g = data[i + 1]!;
const b = data[i + 2]!;
// --- STEP 1: Grayscale Conversion (สูตร Portrait) ---
// ปกติ: r*0.3, g*0.59, b*0.11
// สูตรนี้: เพิ่มน้ำหนัก Red เป็น 0.4 เพื่อให้ "ผิวคน" ดูสว่างขึ้น (Skin Tone Brightening)
let gray = (r * 0.4) + (g * 0.5) + (b * 0.1);
// --- STEP 2: Apply Contrast & Brightness ---
gray = contrastFactor * (gray - 128) + 128 + brightness;
// --- STEP 3: Clamp Values ---
// บังคับค่าให้อยู่ในช่วง 0-255 และกำหนดให้ทั้ง R, G, B เท่ากัน (เพื่อเป็นสีเทา)
const finalGray = Math.max(0, Math.min(255, gray));
data[i] = finalGray; // R
data[i + 1] = finalGray; // G
data[i + 2] = finalGray; // B
// data[i+3] คือ Alpha ไม่ต้องยุ่ง
}
context.putImageData(imageData, 0, 0);
// --- STEP 4: Noir Effect (แสงฟุ้ง + ขอบมืด) ---
// ถ้าปรับ volume เยอะๆ ให้เติมขอบดำ เพื่อให้ดูเป็นสไตล์ Noir/Classic
if (volume > 3) {
addNoirVignette(context, width, height, volume);
}
};
// ฟังก์ชันสร้างขอบดำสำหรับขาวดำโดยเฉพาะ
const addNoirVignette = (ctx: CanvasRenderingContext2D, w: number, h: number, strength: number) => {
// ความเข้มของขอบดำ
const opacity = (strength / 10) * 0.8; // สูงสุด 0.8 (เข้มกว่าแบบฟิล์ม)
const radius = Math.max(w, h) * 0.7; // วงแคบกว่าฟิล์มหน่อย เพื่อเน้นหน้าคนตรงกลาง
const gradient = ctx.createRadialGradient(w/2, h/2, w/4, w/2, h/2, radius);
gradient.addColorStop(0, "rgba(0,0,0,0)");
gradient.addColorStop(1, `rgba(0,0,0,${opacity})`);
ctx.save();
ctx.globalCompositeOperation = 'multiply'; // ใช้ Multiply ให้เงามันซึมลงไปในภาพ
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, w, h);
ctx.restore();
};
const drawDateStamp = (context: CanvasRenderingContext2D, width: number, height: number) => {
const now = new Date();
@@ -118,6 +254,72 @@ const drawDateStamp = (context: CanvasRenderingContext2D, width: number, height:
context.shadowBlur = 0;
};
const applyRetroPop = (context: CanvasRenderingContext2D, width: number, height: number, volume: number = 5) => {
const imageData = context.getImageData(0, 0, width, height);
const data = imageData.data;
// 1. Saturation Factor (ความสด)
// volume 5 = สดขึ้น 50%, volume 10 = สดขึ้น 100% (2 เท่า)
const saturation = 1 + (volume / 10);
// 2. Contrast Factor (ความคมเข้ม)
const contrast = (volume / 10) * 30; // 0-30
const contrastFactor = (259 * (contrast + 255)) / (255 * (259 - contrast));
for (let i = 0; i < data.length; i += 4) {
let r = data[i]!;
let g = data[i + 1]!;
let b = data[i + 2]!;
// --- STEP 1: Apply Contrast First ---
r = contrastFactor * (r - 128) + 128;
g = contrastFactor * (g - 128) + 128;
b = contrastFactor * (b - 128) + 128;
// --- STEP 2: Boost Saturation (หัวใจหลักของฟิลเตอร์นี้) ---
// คำนวณความสว่าง (Luminance) ของ Pixel นั้น
const gray = 0.2989 * r + 0.5870 * g + 0.1140 * b;
// สูตรเร่งสี: สีใหม่ = สีเทา + (สีเดิม - สีเทา) * ความแรง
// ยิ่งค่า Saturation มาก สีจะยิ่งดีดตัวออกจากสีเทา
r = gray + (r - gray) * saturation;
g = gray + (g - gray) * saturation;
b = gray + (b - gray) * saturation;
// --- STEP 3: Color Grading (Retro Vibe) ---
// เพิ่มสี Magenta (แดง+น้ำเงิน) นิดๆ ให้ดูเหมือนนิตยสารยุคเก่า
r *= 1.1; // Boost Red
g *= 0.95; // Reduce Green slightly
b *= 1.05; // Boost Blue slightly
// Clamp values
data[i] = Math.max(0, Math.min(255, r));
data[i + 1] = Math.max(0, Math.min(255, g));
data[i + 2] = Math.max(0, Math.min(255, b));
}
context.putImageData(imageData, 0, 0);
// --- STEP 4: Add Scanlines (Optional) ---
// เพิ่มเส้นขีดๆ เหมือนทีวีรุ่นเก่า (TV Scanlines) เพื่อความ Retro
if (volume > 2) {
addScanlines(context, width, height);
}
};
// ฟังก์ชันวาดเส้นทีวี (ทำให้ดู Retro ยิ่งขึ้น)
const addScanlines = (ctx: CanvasRenderingContext2D, w: number, h: number) => {
ctx.save();
ctx.globalCompositeOperation = "overlay"; // โหมด Overlay ทำให้เส้นกลืนไปกับภาพ
ctx.fillStyle = "rgba(0, 0, 0, 0.1)"; // สีดำจางๆ (ปรับความเข้มที่ 0.1 - 0.3)
// วาดเส้นแนวนอนสลับฟันปลา
for (let y = 0; y < h; y += 4) { // วาดทุกๆ 4 pixel
ctx.fillRect(0, y, w, 2); // ความหนาเส้น 2 pixel
}
ctx.restore();
};
const cropImageTo34 = (imageSrc: string): Promise<string> => {
return new Promise((resolve) => {
const img = new Image();
@@ -172,9 +374,20 @@ const cropImageTo34 = (imageSrc: string): Promise<string> => {
);
// Apply film effect with adjustable volume
applyFilmEffect(context, finalWidth, finalHeight, 7); // Default volume = 5
drawDateStamp(context, finalWidth, finalHeight);
//check local storage name "photobooth-filter"
const filter = localStorage.getItem('photobooth-filter') || 'normal'
if (filter === 'black&white') {
applyBlackAndWhite(context, finalWidth, finalHeight, 3);
} else {
applyFilmEffect(context, finalWidth, finalHeight, 5); // Default volume = 5
}
// applySelfieFilter(context, finalWidth, finalHeight, 10); // Default volume = 5
// applyRetroPop(context, finalWidth, finalHeight, 7);
drawDateStamp(context, finalWidth, finalHeight);
// แปลงเป็น base64 ด้วย quality 0.7 เพื่อลดขนาด
const croppedDataUrl = canvas.toDataURL('image/jpeg', 0.7);
resolve(croppedDataUrl);
@@ -313,10 +526,14 @@ const goBack = () => {
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Crete+Round&family=Old+Standard+TT&display=swap');
.upload-container {
min-height: 100vh;
padding: 2rem;
background: #f8f9fa;
padding: 1.5rem; /* Adjusted padding */
background: #fdfaf6; /* Light vintage paper color */
color: #3e2723; /* Dark brown for text */
font-family: 'Old Standard TT', serif;
display: flex;
flex-direction: column;
}
@@ -326,30 +543,46 @@ const goBack = () => {
align-items: center;
justify-content: space-between;
margin-bottom: 2rem;
background: #e0d8cf; /* Lighter vintage tone for header background */
padding: 1rem 1.5rem;
border-bottom: 1px solid #bcaaa4;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
border-radius: 8px; /* Slightly rounded corners */
}
.back-button {
background: #6c757d;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 8px;
background: #a1887f; /* Vintage brown */
color: #fdfaf6; /* Light text */
border: 1px solid #8d6e63; /* Darker border */
padding: 0.4rem 0.8rem;
border-radius: 5px; /* Softer border-radius */
cursor: pointer;
font-size: 1rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
transition: background 0.2s ease, transform 0.2s ease;
}
.back-button:hover {
background: #8d6e63;
transform: translateY(-1px);
}
.header h1 {
margin: 0;
color: #333;
color: #5d4037; /* Darker brown for title */
font-size: 2rem;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
.photo-counter {
background: #007bff;
color: white;
background: #a1887f; /* Muted brown */
color: #fdfaf6;
padding: 0.5rem 1rem;
border-radius: 20px;
font-weight: bold;
border: 1px solid #8d6e63;
}
.upload-section {
@@ -357,40 +590,46 @@ const goBack = () => {
}
.upload-area {
background: white;
border: 2px dashed #dee2e6;
border-radius: 16px;
padding: 3rem 2rem;
background: #fdfaf6; /* Vintage paper background */
border: 2px dashed #bcaaa4; /* Muted dashed border */
border-radius: 12px; /* Softer border-radius */
padding: 2.5rem 2rem; /* Adjusted padding */
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}
.upload-area:hover {
border-color: #007bff;
background: #f8f9ff;
border-color: #8d6e63; /* Darker brown on hover */
background: #edece9; /* Slightly darker paper on hover */
transform: translateY(-2px);
box-shadow: 0 5px 12px rgba(0,0,0,0.15);
}
.upload-icon {
font-size: 4rem;
margin-bottom: 1rem;
color: #6c757d;
font-size: 3.5rem; /* Slightly smaller icon */
margin-bottom: 0.8rem; /* Adjusted margin */
color: #a1887f; /* Vintage brown for icon */
}
.upload-area h3 {
margin: 0 0 0.5rem 0;
color: #333;
font-size: 1.5rem;
color: #5d4037; /* Darker brown for heading */
font-size: 1.4rem; /* Slightly smaller heading */
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.05);
}
.upload-area p {
margin: 0.5rem 0;
color: #666;
color: #6d4c41; /* Muted brown for paragraph */
font-size: 0.95rem; /* Slightly smaller paragraph font */
}
.file-types {
font-size: 0.9rem;
color: #999;
font-size: 0.85rem;
color: #8d6e63; /* Vintage brown for file types */
}
.hidden-input {
@@ -403,78 +642,86 @@ const goBack = () => {
.preview-section h3 {
margin-bottom: 1rem;
color: #333;
color: #5d4037; /* Darker brown */
text-align: center;
font-family: 'Crete Round', serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.05);
}
.photo-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1rem;
gap: 1.5rem; /* Increased gap */
margin-bottom: 2rem;
}
.photo-item, .photo-placeholder {
position: relative;
aspect-ratio: 3/4;
border-radius: 12px;
border-radius: 8px; /* Softer border-radius */
overflow: hidden;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0,0,0,0.1); /* Subtle shadow */
border: 2px solid #bcaaa4; /* Muted border */
}
.photo-item:hover {
transform: scale(1.02);
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.photo-item img {
width: 100%;
height: 100%;
object-fit: cover;
filter: sepia(0.1) brightness(0.95); /* Subtle sepia and brightness for vintage feel */
}
.remove-button {
position: absolute;
top: 8px;
right: 8px;
background: rgba(220, 53, 69, 0.9);
top: 6px; /* Adjusted position */
right: 6px; /* Adjusted position */
background: #d32f2f; /* Darker red */
color: white;
border: none;
width: 24px;
height: 24px;
width: 26px; /* Slightly larger button */
height: 26px;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
font-size: 0.9rem; /* Slightly larger font */
transition: all 0.3s ease;
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.remove-button:hover {
background: rgba(220, 53, 69, 1);
background: #c62828;
transform: scale(1.1);
}
.photo-number {
position: absolute;
bottom: 8px;
left: 8px;
background: rgba(0,0,0,0.7);
color: white;
width: 24px;
height: 24px;
bottom: 6px; /* Adjusted position */
left: 6px; /* Adjusted position */
background: #8d6e63; /* Vintage brown for number badge */
color: #fdfaf6;
width: 26px; /* Slightly larger badge */
height: 26px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
font-size: 0.9rem;
font-weight: bold;
box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}
.photo-placeholder {
background: #f8f9fa;
border: 2px dashed #dee2e6;
background: #edece9; /* Slightly darker paper background */
border: 2px dashed #a1887f; /* Vintage dashed border */
display: flex;
align-items: center;
justify-content: center;
@@ -482,13 +729,13 @@ const goBack = () => {
}
.photo-placeholder:hover {
border-color: #007bff;
background: #f8f9ff;
border-color: #8d6e63;
background: #e0d8cf; /* Darker on hover */
}
.placeholder-icon {
font-size: 2rem;
color: #6c757d;
font-size: 2.5rem; /* Slightly larger icon */
color: #8d6e63; /* Vintage brown for icon */
}
.action-section {
@@ -497,27 +744,40 @@ const goBack = () => {
}
.next-button {
background: #28a745;
color: white;
border: none;
padding: 1rem 2rem;
font-size: 1.2rem;
background: #8d6e63; /* Vintage brown button */
color: #fdfaf6;
border: 2px solid #795548; /* Darker border */
padding: 1rem 2.5rem;
font-size: 1.3rem;
font-weight: bold;
border-radius: 50px;
border-radius: 8px; /* Softer border-radius */
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(40,167,69,0.3);
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
font-family: 'Crete Round', serif;
text-transform: uppercase;
letter-spacing: 1px;
}
.next-button:hover {
background: #218838;
background: #795548;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(40,167,69,0.4);
box-shadow: 0 6px 15px rgba(0,0,0,0.3);
}
@media (max-width: 768px) {
.photo-grid {
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.header h1 {
font-size: 1.8rem;
}
.upload-area h3 {
font-size: 1.2rem;
}
.next-button {
font-size: 1.1rem;
padding: 0.8rem 2rem;
}
}
</style>

View File

@@ -13,7 +13,7 @@ export default defineConfig({
VitePWA({
registerType: 'autoUpdate',
manifest: {
name: 'DekThai Photobooth',
name: 'Photobooth-APU',
short_name: 'Photobooth',
description: 'Create beautiful photo strips with frames',
theme_color: '#ffffff',
@@ -35,7 +35,7 @@ export default defineConfig({
})
],
server: {
allowedHosts: ['photobooth.lookmeblog.com']
allowedHosts: ['photobooth.lookmeblog.com', 'photobooth.dekthai-online.com']
},
resolve: {
alias: {