You've already forked collage-maker
Serve web files in go
This commit is contained in:
250
web/croppie.css
Normal file
250
web/croppie.css
Normal file
@ -0,0 +1,250 @@
|
||||
.croppie-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.croppie-container .cr-image {
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
transform-origin: 0 0;
|
||||
max-height: none;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.croppie-container .cr-boundary {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin: 0 auto;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.croppie-container .cr-viewport,
|
||||
.croppie-container .cr-resizer {
|
||||
position: absolute;
|
||||
border: 2px solid #fff;
|
||||
margin: auto;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
box-shadow: 0 0 2000px 2000px rgba(0, 0, 0, 0.5);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer {
|
||||
z-index: 2;
|
||||
box-shadow: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-vertical,
|
||||
.croppie-container .cr-resizer-horisontal {
|
||||
position: absolute;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-vertical::after,
|
||||
.croppie-container .cr-resizer-horisontal::after {
|
||||
display: block;
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid black;
|
||||
background: #fff;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
content: '';
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-vertical {
|
||||
bottom: -5px;
|
||||
cursor: row-resize;
|
||||
width: 100%;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-vertical::after {
|
||||
left: 50%;
|
||||
margin-left: -5px;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-horisontal {
|
||||
right: -5px;
|
||||
cursor: col-resize;
|
||||
width: 10px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.croppie-container .cr-resizer-horisontal::after {
|
||||
top: 50%;
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
.croppie-container .cr-original-image {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.croppie-container .cr-vp-circle {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.croppie-container .cr-overlay {
|
||||
z-index: 1;
|
||||
position: absolute;
|
||||
cursor: move;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.croppie-container .cr-slider-wrap {
|
||||
width: 75%;
|
||||
margin: 15px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.croppie-result {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.croppie-result img {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.croppie-container .cr-image,
|
||||
.croppie-container .cr-overlay,
|
||||
.croppie-container .cr-viewport {
|
||||
-webkit-transform: translateZ(0);
|
||||
-moz-transform: translateZ(0);
|
||||
-ms-transform: translateZ(0);
|
||||
transform: translateZ(0);
|
||||
}
|
||||
|
||||
/*************************************/
|
||||
/***** STYLING RANGE INPUT ***********/
|
||||
/*************************************/
|
||||
/*http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html */
|
||||
/*************************************/
|
||||
|
||||
.cr-slider {
|
||||
-webkit-appearance: none;
|
||||
/*removes default webkit styles*/
|
||||
/*border: 1px solid white; *//*fix for FF unable to apply focus style bug */
|
||||
width: 300px;
|
||||
/*required for proper track sizing in FF*/
|
||||
max-width: 100%;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.cr-slider::-webkit-slider-runnable-track {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border: 0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.cr-slider::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
border: none;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
border-radius: 50%;
|
||||
background: #ddd;
|
||||
margin-top: -6px;
|
||||
}
|
||||
|
||||
.cr-slider:focus {
|
||||
outline: none;
|
||||
}
|
||||
/*
|
||||
.cr-slider:focus::-webkit-slider-runnable-track {
|
||||
background: #ccc;
|
||||
}
|
||||
*/
|
||||
|
||||
.cr-slider::-moz-range-track {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border: 0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.cr-slider::-moz-range-thumb {
|
||||
border: none;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
border-radius: 50%;
|
||||
background: #ddd;
|
||||
margin-top: -6px;
|
||||
}
|
||||
|
||||
/*hide the outline behind the border*/
|
||||
.cr-slider:-moz-focusring {
|
||||
outline: 1px solid white;
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
.cr-slider::-ms-track {
|
||||
width: 100%;
|
||||
height: 5px;
|
||||
background: transparent;
|
||||
/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
|
||||
border-color: transparent;/*leave room for the larger thumb to overflow with a transparent border */
|
||||
border-width: 6px 0;
|
||||
color: transparent;/*remove default tick marks*/
|
||||
}
|
||||
.cr-slider::-ms-fill-lower {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.cr-slider::-ms-fill-upper {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.cr-slider::-ms-thumb {
|
||||
border: none;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
border-radius: 50%;
|
||||
background: #ddd;
|
||||
margin-top:1px;
|
||||
}
|
||||
.cr-slider:focus::-ms-fill-lower {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.cr-slider:focus::-ms-fill-upper {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
/*******************************************/
|
||||
|
||||
/***********************************/
|
||||
/* Rotation Tools */
|
||||
/***********************************/
|
||||
.cr-rotate-controls {
|
||||
position: absolute;
|
||||
bottom: 5px;
|
||||
left: 5px;
|
||||
z-index: 1;
|
||||
}
|
||||
.cr-rotate-controls button {
|
||||
border: 0;
|
||||
background: none;
|
||||
}
|
||||
.cr-rotate-controls i:before {
|
||||
display: inline-block;
|
||||
font-style: normal;
|
||||
font-weight: 900;
|
||||
font-size: 22px;
|
||||
}
|
||||
.cr-rotate-l i:before {
|
||||
content: '↺';
|
||||
}
|
||||
.cr-rotate-r i:before {
|
||||
content: '↻';
|
||||
}
|
1625
web/croppie.js
Executable file
1625
web/croppie.js
Executable file
File diff suppressed because it is too large
Load Diff
86
web/index.html
Normal file
86
web/index.html
Normal file
@ -0,0 +1,86 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<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>
|
||||
<!--
|
||||
width: 3264px;
|
||||
height: 4224px;
|
||||
width: 8.5in;
|
||||
height: 11in;
|
||||
-->
|
||||
<style>
|
||||
.image-surface {
|
||||
overflow: hidden;
|
||||
margin: auto;
|
||||
background-color: lightgreen;
|
||||
}
|
||||
.imagebox {
|
||||
grid-area: image;
|
||||
display:flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 50px;
|
||||
flex: 70%;
|
||||
}
|
||||
.container {
|
||||
display: flex;
|
||||
background-color: lightyellow;
|
||||
height: calc(100vh - 20px);
|
||||
}
|
||||
.controls {
|
||||
background-color: lightgrey;
|
||||
display: flex;
|
||||
grid-area: controls;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 30%;
|
||||
}
|
||||
.showbuton {
|
||||
font-size: 2rem;
|
||||
}
|
||||
.letter-portrait {
|
||||
height: 100%;
|
||||
aspect-ratio: 85 / 110;
|
||||
}
|
||||
.letter-portrait .collage-img {
|
||||
height: 50%;
|
||||
}
|
||||
.letter-landscape-2 {
|
||||
display:flex;
|
||||
// width: 80vh;
|
||||
height: 100%;
|
||||
// margin: auto;
|
||||
aspect-ratio: 110 / 85;
|
||||
// aspect-ratio: 7 / 5;
|
||||
gap: 1rem;
|
||||
}
|
||||
.letter-landscape-2 .img1 {
|
||||
flex: 60%;
|
||||
}
|
||||
.letter-landscape-2 .img2 {
|
||||
flex: 40%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="main()">
|
||||
<div class="container">
|
||||
<div class="controls">
|
||||
<button class="showbuton" onClick="snap()">Snap Collage</button>
|
||||
</div>
|
||||
<div class="imagebox">
|
||||
<div id="collage" class="image-surface letter-landscape-2">
|
||||
<div class="collage-img img1" data-collage-image-url="images/img1.jpg">
|
||||
<!-- <img src="img1.jpg"> -->
|
||||
</div>
|
||||
<div class="collage-img img2" data-collage-image-url="images/img2.jpg">
|
||||
<!-- <img src="img2.jpg"> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
107
web/index.js
Normal file
107
web/index.js
Normal file
@ -0,0 +1,107 @@
|
||||
|
||||
function main() {
|
||||
initCollage("collage")
|
||||
}
|
||||
|
||||
function makeCroppieElem(elem, imgUrl) {
|
||||
cpie = new Croppie(elem, {
|
||||
viewport: {
|
||||
width: elem.clientWidth,
|
||||
height: elem.clientHeight,
|
||||
type: 'square'
|
||||
},
|
||||
showZoomer: false,
|
||||
});
|
||||
|
||||
cpie.bind({
|
||||
url: imgUrl
|
||||
});
|
||||
|
||||
return cpie
|
||||
|
||||
}
|
||||
|
||||
// collage state
|
||||
|
||||
var collageDivId;
|
||||
var crops = [];
|
||||
|
||||
function initCollage(divId) {
|
||||
collageDivId = divId
|
||||
const collageDiv = document.getElementById(collageDivId)
|
||||
for(elem of collageDiv.getElementsByClassName("collage-img")) {
|
||||
const cpie = makeCroppieElem(elem, elem.dataset.collageImageUrl)
|
||||
const lastLen = crops.push(cpie)
|
||||
elem.dataset.collageCropieIndex = lastLen - 1
|
||||
}
|
||||
}
|
||||
|
||||
function showCrop() {
|
||||
for(cpie of crops) {
|
||||
console.log(cpie.get())
|
||||
console.log(cpie.element.clientWidth)
|
||||
console.log(cpie.element.clientHeight)
|
||||
}
|
||||
}
|
||||
|
||||
async function ip() {
|
||||
const resp = await fetch("dummy.txt")
|
||||
console.log(await resp.text())
|
||||
}
|
||||
|
||||
function snap() {
|
||||
const collageDiv = document.getElementById(collageDivId)
|
||||
col = collageDiv.offsetLeft;
|
||||
cot = collageDiv.offsetTop;
|
||||
console.log("----------------------")
|
||||
req = {
|
||||
background_image: "",
|
||||
aspect: {
|
||||
width: 528 * 4 * 2,
|
||||
height: 816 * 4,
|
||||
},
|
||||
dimension: {
|
||||
width: collageDiv.clientWidth,
|
||||
height: collageDiv.clientHeight,
|
||||
},
|
||||
photos: [],
|
||||
};
|
||||
|
||||
for(elem of collageDiv.getElementsByClassName("collage-img")) {
|
||||
const cpie = crops[elem.dataset.collageCropieIndex]
|
||||
// console.log(cpie.get().points)
|
||||
// console.log(elem.offsetLeft - col)
|
||||
// console.log(elem.offsetTop - cot)
|
||||
// console.log(elem.clientWidth)
|
||||
// console.log(elem.clientHeight)
|
||||
const fsx = elem.offsetLeft - col
|
||||
const fsy = elem.offsetTop - cot
|
||||
const [sx, sy, ex, ey] = cpie.get().points;
|
||||
const photo = {
|
||||
image: elem.dataset.collageImageUrl,
|
||||
crop: {
|
||||
start: {
|
||||
x: parseInt(sx),
|
||||
y: parseInt(sy),
|
||||
},
|
||||
end: {
|
||||
x: parseInt(ex),
|
||||
y: parseInt(ey),
|
||||
},
|
||||
},
|
||||
frame: {
|
||||
start: {
|
||||
x: fsx,
|
||||
y: fsy,
|
||||
},
|
||||
end: {
|
||||
x: fsx + elem.clientWidth,
|
||||
y: fsy + elem.clientHeight,
|
||||
},
|
||||
},
|
||||
};
|
||||
req.photos.push(photo)
|
||||
}
|
||||
console.log(JSON.stringify(req));
|
||||
ip()
|
||||
}
|
Reference in New Issue
Block a user