You've already forked collage-maker
Compare commits
8 Commits
v0.1.0
...
e10efabcd5
Author | SHA1 | Date | |
---|---|---|---|
e10efabcd5 | |||
7ab601c5ed | |||
8299da3b27 | |||
4578e64597 | |||
a97d98c3e6 | |||
c7e5fb83fc | |||
b432769d6f | |||
b4d58817a5 |
@ -11,7 +11,6 @@ import (
|
||||
"io/fs"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"go.oneofone.dev/resize"
|
||||
)
|
||||
|
||||
type Dimension struct {
|
||||
@ -65,13 +64,13 @@ func Make(req *Request, source fs.FS, output io.Writer) error {
|
||||
}
|
||||
|
||||
destRect := FrameTranslate(req.Aspect, req.Dimension, photo.Frame).ToImgRect()
|
||||
resizedImg := resize.Resize(uint(destRect.Dx()), uint(destRect.Dy()), croppedImage, resize.Lanczos3)
|
||||
resizedImg := imaging.Resize(croppedImage, destRect.Dx(), destRect.Dy(), imaging.Lanczos)
|
||||
draw.Draw(canvas, destRect, resizedImg, image.Point{0, 0}, draw.Src)
|
||||
}
|
||||
var opt jpeg.Options
|
||||
opt.Quality = 100
|
||||
|
||||
return jpeg.Encode(output, canvas, &opt)
|
||||
return jpeg.Encode(output, canvas, &jpeg.Options{
|
||||
Quality: 100,
|
||||
})
|
||||
}
|
||||
|
||||
func FrameTranslate(resolution Dimension, frameSize Dimension, frame Rectangle) Rectangle {
|
||||
|
1
go.mod
1
go.mod
@ -5,7 +5,6 @@ go 1.22
|
||||
require (
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
go.balki.me/anyhttp v0.3.0
|
||||
go.oneofone.dev/resize v1.0.1
|
||||
)
|
||||
|
||||
require golang.org/x/image v0.1.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -3,8 +3,6 @@ github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44am
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.balki.me/anyhttp v0.3.0 h1:WtBQ0rnkg567sX/O4ij/+qBbdCIUt5VURSe718sITBY=
|
||||
go.balki.me/anyhttp v0.3.0/go.mod h1:JhfekOIjgVODoVqUCficjpIgmB3wwlB7jhN0eN2EZ/s=
|
||||
go.oneofone.dev/resize v1.0.1 h1:HjpVar/4pxMGrjO44ThaMX1Q5UOBw0KxzbxxRDZPQuA=
|
||||
go.oneofone.dev/resize v1.0.1/go.mod h1:zGFmn7q4EUZVlnDmxqf+b0mWpxsTt0MH2yx6ng8tpq0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
|
@ -45,3 +45,10 @@
|
||||
border: 5px solid;
|
||||
border-color: red;
|
||||
}
|
||||
|
||||
#notice_dialog button {
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
@ -8,8 +8,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<dialog id="notice_dialog">
|
||||
<p id="notice_p"></p>
|
||||
<form><button type="submit" formmethod="dialog">X</button></form>
|
||||
<form method="dialog"><span id="notice_span"></span><button>X</button></form>
|
||||
</dialog>
|
||||
<div class="container">
|
||||
<div class="controls">
|
||||
|
@ -15,7 +15,7 @@ let makeCollageBtn
|
||||
let albumSelect
|
||||
|
||||
/** @type {HTMLParagraphElement} */
|
||||
let noticeP
|
||||
let noticeSpan
|
||||
|
||||
/** @type {HTMLDialogElement} */
|
||||
let noticeDialog
|
||||
@ -34,7 +34,7 @@ function main() {
|
||||
loadPhotosBtn = document.getElementById("load_photos_button")
|
||||
makeCollageBtn = document.getElementById("make_collage_button")
|
||||
albumSelect = document.getElementById("album_selector")
|
||||
noticeP = document.getElementById("notice_p")
|
||||
noticeSpan = document.getElementById("notice_span")
|
||||
noticeDialog = document.getElementById("notice_dialog")
|
||||
albumPhotosDiv = document.getElementById("album_photos")
|
||||
selectedPhotosDiv = document.getElementById("selected_photos")
|
||||
@ -43,7 +43,7 @@ function main() {
|
||||
loadPhotosBtn.onclick = () => loadPhotos()
|
||||
makeCollageBtn.onclick = () => gotoCollage()
|
||||
|
||||
/** @type HTMLImageElement[] */
|
||||
/** @type HTMLCollectionOf<HTMLImageElement> */
|
||||
const selectedPhotos = selectedPhotosDiv.getElementsByTagName("img")
|
||||
for (const img of selectedPhotos) {
|
||||
img.onclick = () => {
|
||||
@ -55,6 +55,17 @@ function main() {
|
||||
selectedPhotos[0].click()
|
||||
}
|
||||
|
||||
function moveToNextSlot() {
|
||||
/** @type HTMLCollectionOf<HTMLImageElement> */
|
||||
const selectedPhotos = selectedPhotosDiv.getElementsByTagName("img")
|
||||
for (const img of selectedPhotos) {
|
||||
if(img.src.endsWith("stock.svg")) {
|
||||
img.click()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadAlbums() {
|
||||
(async () => {
|
||||
try {
|
||||
@ -81,7 +92,7 @@ function closeNotice() {
|
||||
|
||||
/** @param {string} notice */
|
||||
function showNotice(notice) {
|
||||
noticeP.textContent = notice
|
||||
noticeSpan.textContent = notice
|
||||
noticeDialog.show()
|
||||
}
|
||||
|
||||
@ -110,11 +121,12 @@ function loadPhotos() {
|
||||
albumPhotosDiv.appendChild(img)
|
||||
}
|
||||
|
||||
/** @type HTMLImageElement[] */
|
||||
/** @type HTMLCollectionOf<HTMLImageElement> */
|
||||
const photoImgs = albumPhotosDiv.children
|
||||
for(const photo of photoImgs) {
|
||||
photo.onclick = () => {
|
||||
selectedPhotoImg.src = photo.src
|
||||
moveToNextSlot()
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
@ -124,7 +136,7 @@ function loadPhotos() {
|
||||
}
|
||||
|
||||
function gotoCollage() {
|
||||
/** @type HTMLImageElement[] */
|
||||
/** @type HTMLCollectionOf<HTMLImageElement> */
|
||||
const selectedPhotos = selectedPhotosDiv.getElementsByTagName("img")
|
||||
/** @type String[] */
|
||||
const photoUrls = [];
|
||||
|
@ -9,43 +9,72 @@
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
flex: 25%;
|
||||
overflow: scroll;
|
||||
}
|
||||
.imagebox {
|
||||
padding: 2rem;
|
||||
flex: 75%;
|
||||
}
|
||||
|
||||
:root {
|
||||
--collage-ap: 110 / 85;
|
||||
}
|
||||
|
||||
.image-surface {
|
||||
overflow: hidden;
|
||||
margin: auto;
|
||||
border: 1px solid;
|
||||
height: 100%;
|
||||
width: auto;
|
||||
--collage-ap: 110 / 85;
|
||||
aspect-ratio: var(--collage-ap);
|
||||
}
|
||||
.showbuton {
|
||||
font-size: 2rem;
|
||||
|
||||
.main-controls {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.main-controls button {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
#notice_dialog {
|
||||
z-index: 10;
|
||||
width: 50%;
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
#notice_dialog form {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#notice_dialog button {
|
||||
font-size: 1.2rem;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.templates {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
gap: 0.5rem;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.templates li {
|
||||
width: 30%;
|
||||
list-style-type: none;
|
||||
aspect-ratio: 1 / 1;
|
||||
}
|
||||
|
||||
#page_size_selector {
|
||||
width: 100%;
|
||||
font-size: 1.2rem;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.template {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
aspect-ratio: var(--collage-ap);
|
||||
}
|
||||
|
||||
.template-selected {
|
||||
@ -87,10 +116,10 @@
|
||||
.two-one-two-topbottom {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"A B"
|
||||
"C C"
|
||||
"C C"
|
||||
"D E"
|
||||
"A B"
|
||||
"C C"
|
||||
"C C"
|
||||
"D E";
|
||||
}
|
||||
|
||||
.two-one-two-topbottom .img1 {
|
||||
@ -100,17 +129,27 @@
|
||||
.two-row {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"A B"
|
||||
"A B";
|
||||
}
|
||||
|
||||
.three-row {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"A B C"
|
||||
"A B C";
|
||||
}
|
||||
|
||||
.four-row {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"A B C D"
|
||||
"A B C D";
|
||||
}
|
||||
|
||||
.one-three-topbottom {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"A A A"
|
||||
"B C D";
|
||||
}
|
||||
.one-three-topbottom .img1 {
|
||||
grid-area: A;
|
||||
}
|
||||
|
@ -9,22 +9,29 @@
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
</head>
|
||||
<body>
|
||||
<dialog id="notice_dialog">
|
||||
<form method="dialog"><span><a href="" target="_blank" id="collage-url"></a></span><button>X</button></form>
|
||||
</dialog>
|
||||
<div class="container">
|
||||
<div class="controls">
|
||||
|
||||
<p><a href="choose.html">Select Images</a></p>
|
||||
<h1>Photo Collage</h1>
|
||||
<select id="page_size_selector">
|
||||
<option value="letter-portrait" > Letter (Portrait) </option>
|
||||
<option selected value="letter-landscape" > Letter (Landscape) </option>
|
||||
<option value="fiveseven-portrait" > 5 × 7 (Portrait) </option>
|
||||
<option value="fiveseven-landscape" > 7 × 5 (Landscape) </option>
|
||||
<option value="foursix-portrait" > 4 × 6 (Portrait) </option>
|
||||
<option value="foursix-landscape" > 4 × 6 (Landscape) </option>
|
||||
</select>
|
||||
<div class="main-controls">
|
||||
<a href="choose.html"><button>Select</button></a>
|
||||
|
||||
<button id="snapper" class="showbuton">Snap</button>
|
||||
<a href="/collages/?layout=grid" target="_blank" ><button>All</button></a>
|
||||
</div>
|
||||
|
||||
|
||||
<label>
|
||||
<span>Paper size</span>
|
||||
<select id="page_size_selector" size=6>
|
||||
<option value="letter-portrait" > Letter (Portrait) </option>
|
||||
<option selected value="letter-landscape" > Letter (Landscape) </option>
|
||||
<option value="fiveseven-portrait" > 5 × 7 (Portrait) </option>
|
||||
<option value="fiveseven-landscape" > 7 × 5 (Landscape) </option>
|
||||
<option value="foursix-portrait" > 4 × 6 (Portrait) </option>
|
||||
<option value="foursix-landscape" > 4 × 6 (Landscape) </option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
|
||||
<ul class="templates">
|
||||
@ -113,10 +120,35 @@
|
||||
<div class="img img12"></div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="template three-row">
|
||||
<div class="img img1"></div>
|
||||
<div class="img img2"></div>
|
||||
<div class="img img3"></div>
|
||||
<div class="img img4"></div>
|
||||
<div class="img img5"></div>
|
||||
<div class="img img6"></div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="template two-row">
|
||||
<div class="img img1"></div>
|
||||
<div class="img img2"></div>
|
||||
<div class="img img3"></div>
|
||||
<div class="img img4"></div>
|
||||
<div class="img img5"></div>
|
||||
<div class="img img6"></div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="template one-three-topbottom">
|
||||
<div class="img img1"></div>
|
||||
<div class="img img2"></div>
|
||||
<div class="img img3"></div>
|
||||
<div class="img img4"></div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<button id="snapper" class="showbuton">Snap Collage</button>
|
||||
<p><a href="" target="_blank" id="collage-url"></a></p>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="imagebox">
|
||||
|
@ -44,6 +44,9 @@ let collageDiv
|
||||
/** @type {HTMLSelectElement} */
|
||||
let pageSizeSelect
|
||||
|
||||
/** @type {HTMLDialogElement} */
|
||||
let noticeDialog
|
||||
|
||||
/** @type {HTMLAnchorElement} */
|
||||
let collageUrlA
|
||||
|
||||
@ -59,6 +62,7 @@ function main() {
|
||||
snapButton = document.getElementById("snapper")
|
||||
collageDiv = document.getElementById("collage")
|
||||
pageSizeSelect = document.getElementById("page_size_selector")
|
||||
noticeDialog = document.getElementById("notice_dialog")
|
||||
collageUrlA = document.getElementById("collage-url")
|
||||
|
||||
snapButton.onclick = () => snap()
|
||||
@ -74,6 +78,7 @@ function main() {
|
||||
// Skipping first entry in array to make the images start with index 1
|
||||
imageUrls = [,].concat(queryUrls)
|
||||
|
||||
pageSizeChange()
|
||||
applyTemplate(document.getElementById("default_template"))
|
||||
}
|
||||
|
||||
@ -171,6 +176,7 @@ function snap() {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
noticeDialog.show()
|
||||
collageUrlA.text = "Collage is being generated...";
|
||||
const collagFile = await makeCollage(req)
|
||||
collageUrlA.href = `collages/${collagFile}`;
|
||||
@ -179,7 +185,8 @@ function snap() {
|
||||
}
|
||||
|
||||
function pageSizeChange() {
|
||||
collageDiv.style.setProperty('--collage-ap', pageSizes[pageSizeSelect.value]["ap"])
|
||||
// https://stackoverflow.com/a/37802204
|
||||
document.documentElement.style.setProperty('--collage-ap', pageSizes[pageSizeSelect.value]["ap"])
|
||||
pageSize = pageSizeSelect.value
|
||||
initCollage()
|
||||
}
|
||||
|
Reference in New Issue
Block a user