add page size select
This commit is contained in:
parent
9dceae06a7
commit
00bc166148
1
main.go
1
main.go
@ -126,7 +126,6 @@ func MakeCollage(req *collage.Request) (string, error) {
|
||||
out, err := os.Create(path.Join(collageDir, collageFile))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create collage output file, err: %w", err)
|
||||
// slog.Error("failed to create collage output file", "error", err)
|
||||
}
|
||||
if err := collage.Make(req, imagesDirFs, out); err != nil {
|
||||
return "", fmt.Errorf("failed to make collage, err: %w", err)
|
||||
|
@ -14,12 +14,15 @@
|
||||
padding: 2rem;
|
||||
flex: 70%;
|
||||
}
|
||||
|
||||
.image-surface {
|
||||
overflow: hidden;
|
||||
margin: auto;
|
||||
border: 1px solid;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
width: auto;
|
||||
--collage-ap: 110 / 85;
|
||||
aspect-ratio: var(--collage-ap);
|
||||
}
|
||||
.showbuton {
|
||||
font-size: 2rem;
|
||||
|
@ -4,8 +4,8 @@
|
||||
<link rel="stylesheet" href="croppie.css" />
|
||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
|
||||
<script src="http://localhost:35729/livereload.js"></script>
|
||||
<script src="croppie.js"></script>
|
||||
<script src="index.js"></script>
|
||||
<script src="croppie.js" defer></script>
|
||||
<script src="index.js" defer></script>
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
<!--
|
||||
width: 3264px;
|
||||
@ -14,16 +14,29 @@
|
||||
height: 11in;
|
||||
-->
|
||||
</head>
|
||||
<body onload="main()">
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="controls">
|
||||
<div>
|
||||
<button class="showbuton" onClick="snap()">Snap Collage</button>
|
||||
<div>
|
||||
<label>
|
||||
Page size
|
||||
<select id="page_size_selector" size=8 onChange="pageSizeChange(this)">
|
||||
<option value="letter-portrait">Letter (Portrait)</option>
|
||||
<option selected value="letter-landscape">Letter (Landscape)</option>
|
||||
<option value="fiveseven-portrait">5 X 7 (Portrait)</option>
|
||||
<option value="fiveseven-landscape">7 X 5 (Landscape)</option>
|
||||
<option value="foursix-portrait">4 X 6 (Portrait)</option>
|
||||
<option value="foursix-landscape">4 X 6 (Landscape)</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<button id="snapper" class="showbuton">Snap Collage</button>
|
||||
<p><a href="" target="_blank" id="collage-url"></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="imagebox">
|
||||
<div id="collage" class="image-surface fiveseven-landscape one-two">
|
||||
<div id="collage" class="image-surface one-two">
|
||||
<div class="collage-img img1" data-collage-image-url="images/img1.jpg">
|
||||
</div>
|
||||
<div class="collage-img img2" data-collage-image-url="images/img2.jpg">
|
||||
|
78
web/index.js
78
web/index.js
@ -1,6 +1,54 @@
|
||||
const pageSizes = {
|
||||
"letter-portrait" : {
|
||||
"ap": "85 / 110",
|
||||
"width": 3264,
|
||||
"height": 4224,
|
||||
},
|
||||
"letter-landscape" : {
|
||||
"ap": "110 / 85",
|
||||
"width": 4224,
|
||||
"height": 3264,
|
||||
},
|
||||
"fiveseven-portrait" : {
|
||||
"ap": "5 / 7",
|
||||
"width": 2250,
|
||||
"height": 3150,
|
||||
},
|
||||
"fiveseven-landscape" : {
|
||||
"ap": "7 / 5",
|
||||
"width": 3150,
|
||||
"height": 2250,
|
||||
},
|
||||
"foursix-portrait" : {
|
||||
"ap": "4 / 6",
|
||||
"width": 1800,
|
||||
"height": 2700,
|
||||
},
|
||||
"foursix-landscape" : {
|
||||
"ap": "6 / 4",
|
||||
"width": 2700,
|
||||
"height": 1800,
|
||||
},
|
||||
}
|
||||
|
||||
// elements -- dummy createElement for language server type hint
|
||||
var snapButton = document.createElement("button")
|
||||
var collageDiv = document.createElement("div")
|
||||
var pageSizeSelect = document.createElement("select")
|
||||
var collageUrlA = document.createElement("a");
|
||||
|
||||
// collage state
|
||||
var crops = [];
|
||||
var pageSize = "letter-landscape";
|
||||
|
||||
function main() {
|
||||
initCollage("collage")
|
||||
snapButton = document.getElementById("snapper")
|
||||
collageDiv = document.getElementById("collage")
|
||||
pageSizeSelect = document.getElementById("page_size_selector")
|
||||
collageUrlA = document.getElementById("collage-url")
|
||||
initCollage()
|
||||
snapButton.onclick = () => snap()
|
||||
pageSizeSelect.onchange = () => pageSizeChange(pageSizeSelect)
|
||||
}
|
||||
|
||||
function makeCroppieElem(elem, imgUrl) {
|
||||
@ -18,17 +66,14 @@ function makeCroppieElem(elem, imgUrl) {
|
||||
});
|
||||
|
||||
return cpie
|
||||
|
||||
}
|
||||
|
||||
// collage state
|
||||
|
||||
var collageDivId;
|
||||
var crops = [];
|
||||
|
||||
function initCollage(divId) {
|
||||
collageDivId = divId
|
||||
const collageDiv = document.getElementById(collageDivId)
|
||||
function initCollage() {
|
||||
for(cpie of crops) {
|
||||
cpie.destroy()
|
||||
}
|
||||
crops = []
|
||||
for(elem of collageDiv.getElementsByClassName("collage-img")) {
|
||||
const cpie = makeCroppieElem(elem, elem.dataset.collageImageUrl)
|
||||
const lastLen = crops.push(cpie)
|
||||
@ -56,15 +101,14 @@ async function makeCollage(req) {
|
||||
}
|
||||
|
||||
function snap() {
|
||||
const collageDiv = document.getElementById(collageDivId)
|
||||
col = collageDiv.offsetLeft;
|
||||
cot = collageDiv.offsetTop;
|
||||
console.log("----------------------")
|
||||
req = {
|
||||
background_image: "",
|
||||
aspect: {
|
||||
width: 3150,
|
||||
height: 2250,
|
||||
width: pageSizes[pageSize]["width"],
|
||||
height: pageSizes[pageSize]["height"],
|
||||
},
|
||||
dimension: {
|
||||
width: collageDiv.clientWidth,
|
||||
@ -112,9 +156,15 @@ function snap() {
|
||||
console.log(JSON.stringify(req));
|
||||
(async () => {
|
||||
collagFile = await makeCollage(req)
|
||||
// const collageUrlA = document.createElement("a");
|
||||
const collageUrlA = document.getElementById("collage-url");
|
||||
collageUrlA.href = `collages/${collagFile}`;
|
||||
collageUrlA.text = `${collagFile} generated`;
|
||||
})();
|
||||
}
|
||||
|
||||
function pageSizeChange(selectElem) {
|
||||
document.getElementById("collage").style.setProperty('--collage-ap', pageSizes[selectElem.value]["ap"])
|
||||
pageSize = selectElem.value
|
||||
initCollage()
|
||||
}
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user