poff-bnff / web2021

1 stars 0 forks source link

CG1: Person Pro vorm ja uus autentimine #689

Open jaanleppik opened 8 months ago

jaanleppik commented 8 months ago

eelmise autentimisega sai kasutaja OMA pro profiili täita (keerulisimad osad on autentimine, valideerimise ja ja korratavad komponendid - aga need töötasid enam vähem)

Eesmärk:

Kontekst:

Ülesanded

mitselek commented 7 months ago

Here's a basic example of how you might manipulate EXIF data using JavaScript in a browser:

Include the exif-js library in your HTML file. You can download it from https://github.com/exif-js/exif-js or include it from a CDN.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EXIF Data Manipulation</title>
    <script src="path/to/exif.js"></script>
</head>
<body>
    <!-- Your HTML content here -->

    <script src="your_script.js"></script>
</body>
</html>

Create a JavaScript file (e.g., your_script.js) to handle the manipulation:

// Your function to manipulate EXIF data
function manipulateEXIF(fileInput) {
    const file = fileInput.files[0];

    // Use FileReader to read the image file
    const reader = new FileReader();
    reader.onload = function (e) {
        const image = new Image();
        image.src = e.target.result;

        // Use exif-js to read and modify EXIF data
        EXIF.getData(image, function() {
            // Access and modify EXIF data as needed
            const originalDateTime = EXIF.getTag(this, "DateTimeOriginal");
            console.log("Original DateTime:", originalDateTime);

            // Example: Change DateTimeOriginal to the current date and time
            const newDateTime = new Date();
            EXIF.setTag(this, "DateTimeOriginal", newDateTime);

            // Access the modified EXIF data
            const modifiedDateTime = EXIF.getTag(this, "DateTimeOriginal");
            console.log("Modified DateTime:", modifiedDateTime);

            // Now you can use the modified image data as needed
            const modifiedImageData = this.toDataURL();
            console.log("Modified Image Data:", modifiedImageData);
        });
    };

    // Read the file as a data URL
    reader.readAsDataURL(file);
}

// Attach the function to the file input change event
const fileInput = document.getElementById("fileInput"); // Make sure to add an id to your file input
fileInput.addEventListener("change", function () {
    manipulateEXIF(this);
});

Remember to replace "path/to/exif.js" with the actual path to the exif.js file or use a CDN link. Additionally, ensure that you have a file input element in your HTML with an id, as shown in the example.

Keep in mind that manipulating EXIF data in the browser using JavaScript may have limitations due to browser security policies, especially for modifying data. Always test thoroughly and consider server-side solutions if needed.