-1
I made a code in jQuery that when loading an image (input file
) I pick a photo and that photo goes to the site of input
However the photo does not appear to measure, it is deformed. I do not know how to make it fit automatically.
I wanted to do something like Facebook, we chose a photo and it appears adjusted in the circle.
How do I do this?
The code is as follows::
HTML:
<center class="m-t-30">
<div id="profile-container">
<img src="/assets/images/users/user.png" class="rounded-circle" width="150" id="profileImage" style="cursor: pointer;" />
</div>
</center>
<br>
<input type="file" accept="image/*" id="imageUpload" style="display: none;" capture>
CSS:
#profile-container {
width: 150px;
height: 150px;
overflow: hidden;
-webkit-border-radius: 50% !important;
-moz-border-radius: 50% !important;
-ms-border-radius: 50% !important;
-o-border-radius: 50% !important;
border-radius: 50% !important
}
#profile-container img {
width: 150px;
height: 150px;
}
.rounded-circle {
border-radius: 50% !important
}
Javascript:
document.querySelector('#profileImage').addEventListener('click', function (e){
$('#imageUpload').click();
});
document.querySelector('#imageUpload').addEventListener('change', function () {
if (this.files && this.files[0]) {
$('#profileImage').attr('src', window.URL.createObjectURL(this.files[0]));
}
});
The code works, only when selecting the image, it is flattened.
Ana, I don’t mean to be rude, but how do you want help without putting your code in the question? Edit your question, put your code, then we can evaluate what you did and tell you where you went wrong or a possible solution.
– hugocsl
Question without information,?
– Maury Developer
Ah yes...I didn’t know it was necessary...I’ll put it on...
– Ana Xavier