Skip to content

Commit

Permalink
Merge pull request #15 from brunopicinin/webp-support
Browse files Browse the repository at this point in the history
Add support for WebP image format
  • Loading branch information
capjamesg authored Oct 3, 2024
2 parents 28c953d + b148cb2 commit 0c0479b
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,20 @@ canvas.addEventListener('mousemove', function(e) {
canvas.addEventListener('drop', function(e) {
e.preventDefault();
var file = e.dataTransfer.files[0];

// only allow image files
var supportedImageTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/webp'];
if (!supportedImageTypes.includes(file.type)) {
alert('Only PNG, JPEG, JPG, and WebP files are allowed.');
return;
}

var reader = new FileReader();

reader.onload = function(event) {
// only allow image files
img.src = event.target.result;
};
reader.readAsDataURL(file);

var mime_type = file.type;

if (
mime_type != 'image/png' &&
mime_type != 'image/jpeg' &&
mime_type != 'image/jpg'
) {
alert('Only PNG, JPEG, and JPG files are allowed.');
return;
}

img.onload = function() {
scaleFactor = 0.25;
canvas.style.width = img.width * scaleFactor + 'px';
Expand Down

0 comments on commit 0c0479b

Please sign in to comment.