Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
844048cb54
13 files changed
+1328
-24
No files matched your search
+383
@@ -0,0 +1,383 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Editor de Documentos</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/cropperjs@1.5.12/dist/cropper.min.css" rel="stylesheet">
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-family: Arial, sans-serif;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
.editor-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
padding: 15px;
|
||||
box-sizing: border-box;
|
||||
gap: 15px;
|
||||
}
|
||||
.img-container {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
max-height: calc(100vh - 300px);
|
||||
}
|
||||
.controls-section {
|
||||
flex: 0 0 auto;
|
||||
background: #fff;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.controls {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.range-control {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.range-control label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.range-control input[type="range"] {
|
||||
width: 100%;
|
||||
}
|
||||
.toolbar {
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.toolbar button {
|
||||
margin: 0 5px;
|
||||
padding: 8px 15px;
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.toolbar button:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
#preview {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
.cropper-container {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
}
|
||||
.cropper-wrap-box {
|
||||
background-color: #fff;
|
||||
}
|
||||
.thumbnails {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
overflow-x: auto;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.thumbnail {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
object-fit: cover;
|
||||
cursor: pointer;
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
.thumbnail.active {
|
||||
border-color: #4CAF50;
|
||||
}
|
||||
#preview-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#preview-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="editor-container">
|
||||
<div class="thumbnails" id="thumbnails">
|
||||
<!-- Miniaturas serão inseridas aqui -->
|
||||
</div>
|
||||
|
||||
<div class="img-container">
|
||||
<div id="preview-container">
|
||||
<img id="preview" src="">
|
||||
<canvas id="preview-canvas"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls-section">
|
||||
<div class="controls">
|
||||
<div class="range-control">
|
||||
<label>Brilho</label>
|
||||
<input type="range" min="-100" max="100" value="0" id="brightness" oninput="adjustImage()">
|
||||
<span id="brightnessValue">0</span>
|
||||
</div>
|
||||
<div class="range-control">
|
||||
<label>Contraste</label>
|
||||
<input type="range" min="-100" max="100" value="0" id="contrast" oninput="adjustImage()">
|
||||
<span id="contrastValue">0</span>
|
||||
</div>
|
||||
<div class="range-control">
|
||||
<label>Saturação</label>
|
||||
<input type="range" min="-100" max="100" value="0" id="saturation" oninput="adjustImage()">
|
||||
<span id="saturationValue">0</span>
|
||||
</div>
|
||||
<div class="range-control">
|
||||
<label>Matiz</label>
|
||||
<input type="range" min="-180" max="180" value="0" id="hue" oninput="adjustImage()">
|
||||
<span id="hueValue">0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<button onclick="resetImage()">Resetar</button>
|
||||
<button onclick="rotateCCW()">Girar Esquerda</button>
|
||||
<button onclick="rotateCW()">Girar Direita</button>
|
||||
<button onclick="cropImage()">Recortar</button>
|
||||
<button onclick="autoAdjust()">Otimização Automática</button>
|
||||
<button onclick="combineImages()" style="background: #FF9800;">Unir Imagens</button>
|
||||
<button onclick="saveImage()" style="background: #2196F3;">Salvar</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/cropperjs@1.5.12/dist/cropper.min.js"></script>
|
||||
<script>
|
||||
let cropper;
|
||||
let images = [];
|
||||
let currentImageIndex = 0;
|
||||
let filters = {
|
||||
brightness: 100,
|
||||
contrast: 100,
|
||||
saturation: 100,
|
||||
hue: 0
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
const fileCount = parseInt(localStorage.getItem('fileCount')) || 1;
|
||||
const baseUrl = localStorage.getItem('tempImage');
|
||||
|
||||
// Carregar todas as imagens
|
||||
for (let i = 0; i < fileCount; i++) {
|
||||
const url = baseUrl.replace('.', `_${i}.`);
|
||||
images.push({
|
||||
url: url,
|
||||
filters: { ...filters }
|
||||
});
|
||||
}
|
||||
|
||||
// Criar miniaturas
|
||||
const thumbnailsContainer = document.getElementById('thumbnails');
|
||||
images.forEach((image, index) => {
|
||||
const thumb = document.createElement('img');
|
||||
thumb.src = image.url;
|
||||
thumb.className = 'thumbnail' + (index === 0 ? ' active' : '');
|
||||
thumb.onclick = () => switchImage(index);
|
||||
thumbnailsContainer.appendChild(thumb);
|
||||
});
|
||||
|
||||
// Inicializar com primeira imagem
|
||||
initCropper(images[0].url);
|
||||
};
|
||||
|
||||
function initCropper(url) {
|
||||
const preview = document.getElementById('preview');
|
||||
preview.src = url;
|
||||
|
||||
if (cropper) {
|
||||
cropper.destroy();
|
||||
}
|
||||
|
||||
cropper = new Cropper(preview, {
|
||||
viewMode: 2,
|
||||
dragMode: 'move',
|
||||
autoCropArea: 1,
|
||||
restore: false,
|
||||
modal: true,
|
||||
guides: true,
|
||||
highlight: true,
|
||||
cropBoxMovable: true,
|
||||
cropBoxResizable: true,
|
||||
toggleDragModeOnDblclick: true,
|
||||
ready: function() {
|
||||
applyCurrentFilters();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function switchImage(index) {
|
||||
currentImageIndex = index;
|
||||
document.querySelectorAll('.thumbnail').forEach((thumb, i) => {
|
||||
thumb.className = 'thumbnail' + (i === index ? ' active' : '');
|
||||
});
|
||||
initCropper(images[index].url);
|
||||
}
|
||||
|
||||
function adjustImage() {
|
||||
filters = {
|
||||
brightness: parseInt(document.getElementById('brightness').value) + 100,
|
||||
contrast: parseInt(document.getElementById('contrast').value) + 100,
|
||||
saturation: parseInt(document.getElementById('saturation').value) + 100,
|
||||
hue: parseInt(document.getElementById('hue').value)
|
||||
};
|
||||
|
||||
applyCurrentFilters();
|
||||
}
|
||||
|
||||
function applyCurrentFilters() {
|
||||
const canvas = cropper.getCroppedCanvas();
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Aplicar filtros
|
||||
ctx.filter = `brightness(${filters.brightness}%)
|
||||
contrast(${filters.contrast}%)
|
||||
saturate(${filters.saturation}%)
|
||||
hue-rotate(${filters.hue}deg)`;
|
||||
|
||||
// Redesenhar com filtros
|
||||
ctx.drawImage(canvas, 0, 0);
|
||||
|
||||
// Atualizar preview
|
||||
const previewCanvas = document.getElementById('preview-canvas');
|
||||
const pctx = previewCanvas.getContext('2d');
|
||||
pctx.clearRect(0, 0, previewCanvas.width, previewCanvas.height);
|
||||
pctx.filter = ctx.filter;
|
||||
pctx.drawImage(canvas, 0, 0);
|
||||
}
|
||||
|
||||
async function combineImages() {
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
let totalHeight = 0;
|
||||
let maxWidth = 0;
|
||||
|
||||
// Primeiro passo: calcular dimensões
|
||||
for (let image of images) {
|
||||
const img = await createImage(image.url);
|
||||
maxWidth = Math.max(maxWidth, img.width);
|
||||
totalHeight += img.height;
|
||||
}
|
||||
|
||||
// Configurar canvas
|
||||
canvas.width = maxWidth;
|
||||
canvas.height = totalHeight;
|
||||
|
||||
// Segundo passo: desenhar imagens
|
||||
let currentY = 0;
|
||||
for (let image of images) {
|
||||
const img = await createImage(image.url);
|
||||
ctx.drawImage(img, 0, currentY);
|
||||
currentY += img.height;
|
||||
}
|
||||
|
||||
// Atualizar preview
|
||||
initCropper(canvas.toDataURL('image/jpeg'));
|
||||
}
|
||||
|
||||
function createImage(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve(img);
|
||||
img.onerror = reject;
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
function resetImage() {
|
||||
cropper.reset();
|
||||
document.querySelectorAll('input[type="range"]').forEach(input => {
|
||||
input.value = 0;
|
||||
document.getElementById(input.id + 'Value').textContent = '0';
|
||||
});
|
||||
adjustImage();
|
||||
}
|
||||
|
||||
function rotateCW() {
|
||||
cropper.rotate(90);
|
||||
}
|
||||
|
||||
function rotateCCW() {
|
||||
cropper.rotate(-90);
|
||||
}
|
||||
|
||||
function cropImage() {
|
||||
cropper.setDragMode('crop');
|
||||
}
|
||||
|
||||
function autoAdjust() {
|
||||
// Implementar otimização automática aqui
|
||||
alert('Função em desenvolvimento');
|
||||
}
|
||||
|
||||
function saveImage() {
|
||||
const canvas = cropper.getCroppedCanvas({
|
||||
maxWidth: 4096,
|
||||
maxHeight: 4096,
|
||||
fillColor: '#fff',
|
||||
imageSmoothingEnabled: true,
|
||||
imageSmoothingQuality: 'high',
|
||||
});
|
||||
|
||||
canvas.toBlob(function(blob) {
|
||||
const formData = new FormData();
|
||||
formData.append('image', blob);
|
||||
formData.append('client_id', localStorage.getItem('tempClientId'));
|
||||
formData.append('doc_type', localStorage.getItem('tempDocType'));
|
||||
|
||||
fetch('index.php?page=save_edited', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(async response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (!contentType || !contentType.includes("application/json")) {
|
||||
throw new TypeError("Oops, não recebemos JSON!");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
window.parent.postMessage({
|
||||
type: 'documentSaved',
|
||||
data: data
|
||||
}, '*');
|
||||
} else {
|
||||
throw new Error(data.message || 'Erro desconhecido');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erro ao salvar:', error);
|
||||
alert('Erro ao salvar documento: ' + error.message);
|
||||
});
|
||||
}, 'image/jpeg', 0.95);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user