Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding default images and fixing export
  • Loading branch information
kmr18006 committed Apr 19, 2024
1 parent e1cbc60 commit 8a1bad4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion final project/css/style.css
Expand Up @@ -212,7 +212,7 @@ ul {
}
.main {
grid-template-columns: 1fr;
height: 88vh;
height: 93vh;
}
.tools {
height:auto;
Expand Down
Binary file added final project/img/cutecat2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added final project/img/cutecat3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added final project/img/cutecat4.webp
Binary file not shown.
6 changes: 5 additions & 1 deletion final project/index.html
Expand Up @@ -9,6 +9,7 @@
<link rel="stylesheet" href="https://use.typekit.net/xpy5krv.css">
<link rel="stylesheet" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<meta name="description" content="Collage maker where you can drag images from you files and move, resize, rotate, move to the front, or delete to create a collage.">

</head>
Expand Down Expand Up @@ -53,7 +54,10 @@
</div>

<div class="collage" id="collage">
<canvas id="canvas"></canvas>
<img src="img/cutecat.jpg" alt="cute cat!">
<img src="img/cutecat2.jpg" alt="another cute cat" style="left: 800px">
<img src="img/cutecat3.jpg" alt="omg its another cute cat" style="left: 500px; top: 100px;">
<img src="img/cutecat4.webp" alt="okay last cute cat hehe" style=" left: 100px; top: 300px;">
</div>


Expand Down
26 changes: 7 additions & 19 deletions final project/js/script.js
Expand Up @@ -40,7 +40,7 @@ function whileDragging(e) {
return false;

if (mode == 0) {
var newX = e.pageX - 600;
var newX = e.pageX - 400;
var newY = e.pageY - 200;
currentlyDragging.css({ 'margin-top': newY + 'px', 'margin-left': newX + 'px' });
} else if (mode == 1) {
Expand Down Expand Up @@ -106,25 +106,13 @@ $(document).ready(function () {
}

function saveCollage() {
var canvas = document.createElement('canvas');
var collage = $('#collage')[0];
var ctx = canvas.getContext('2d');

// Set canvas size to match collage size
canvas.width = collage.offsetWidth;
canvas.height = collage.offsetHeight;

// Draw images from collage onto canvas
$(collage).find('img').each(function(index, image) {
ctx.drawImage(image, image.offsetLeft, image.offsetTop, image.width, image.height);
html2canvas(document.getElementById('collage')).then(function(canvas) {
var dataURL = canvas.toDataURL('image/png');
var a = document.createElement('a');
a.href = dataURL;
a.download = 'collage.png';
a.click();
});

// Generate data URL and initiate download
var dataURL = canvas.toDataURL('image/png');
var a = document.createElement('a');
a.href = dataURL;
a.download = 'collage.png';
a.click();
}
});

Expand Down

0 comments on commit 8a1bad4

Please sign in to comment.