Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="UTF-8">
- <link rel="shortcut icon" type="image/jpg" href="favicon.png"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Renomear arquivo online e Inserir Data</title>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap">
- <style>
- body {
- font-family: 'Poppins', sans-serif;
- background-color: #f0f0f0;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 100vh;
- margin: 0;
- }
- .container {
- text-align: center;
- color: #333;
- }
- form {
- background-color: #ffffff;
- padding: 20px;
- border-radius: 8px;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
- display: flex;
- flex-direction: column;
- align-items: center;
- margin-top: 20px;
- }
- input, button {
- margin-bottom: 10px;
- padding: 10px;
- width: 100%;
- box-sizing: border-box;
- }
- button {
- cursor: pointer;
- background-color: #0074D9; /* Cor azul */
- color: white;
- border: none;
- border-radius: 4px;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #0056b3; /* Cor azul mais escura no hover */
- }
- </style>
- </head>
- <body>
- <form id="uploadForm">
- <label for="fileInput"><h2>Renomear arquivo online e Inserir Data</h2></label>
- <br>O tamanho do arquivo deve ser no máximo 10 MB.<br>
- <p>O nome do arquivo será no formato <b>aaaa-mm-dd-hh-mm-ss</b></p>
- <input type="file" id="fileInput" accept="image/*" required>
- <button type="button" onclick="uploadFile()">Enviar</button>
- </form>
- <script>
- function uploadFile() {
- var fileInput = document.getElementById('fileInput');
- var file = fileInput.files[0];
- // Verificar se um arquivo foi selecionado
- if (!file) {
- alert("Por favor, selecione um arquivo.");
- return;
- }
- // Verificar o tamanho do arquivo (10 MB = 10 * 1024 * 1024 bytes)
- if (file.size > 10 * 1024 * 1024) {
- alert("O tamanho do arquivo deve ser no máximo 10 MB.");
- return;
- }
- var currentDate = new Date();
- var uniqueFileName = currentDate.getFullYear() + '-' +
- pad(currentDate.getMonth() + 1) + '-' +
- pad(currentDate.getDate()) + '-' +
- pad(currentDate.getHours()) + '-' +
- pad(currentDate.getMinutes()) + '-' +
- pad(currentDate.getSeconds());
- var fileExtension = file.name.split('.').pop();
- var newFileName = uniqueFileName + "." + fileExtension;
- // Criar um canvas para adicionar a data à imagem
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- var img = new Image();
- img.onload = function() {
- canvas.width = img.width;
- canvas.height = img.height;
- ctx.drawImage(img, 0, 0);
- ctx.font = 'bold 40px Arial'; // Aumentando o tamanho da fonte
- ctx.fillStyle = '#FFFFFF';
- ctx.textAlign = 'right';
- ctx.textBaseline = 'bottom';
- ctx.fillText(pad(currentDate.getDate()) + '/' +
- pad(currentDate.getMonth() + 1) + '/' +
- currentDate.getFullYear(),
- canvas.width - 10, canvas.height - 10);
- canvas.toBlob(function(blob) {
- var link = document.createElement('a');
- link.href = window.URL.createObjectURL(blob);
- link.download = newFileName;
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }, file.type);
- };
- img.src = URL.createObjectURL(file);
- }
- function pad(number) {
- return (number < 10 ? '0' : '') + number;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement