Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
Change Profile Picture in Javascript Issue

So, I have this Javascript code, which is responsible for changing our profile picture image. So the changing part is working absolutely fine, I can upload a file, and change the image. So, when you log in, you get a default profile picture, which then you can click on a button to change your profile image. So, that particular default image, is an image with a border-radius of 25 px. So, the only problem which I'm encountering now is that, when I upload the image, it should upload and be uploaded as having a border radius of 25 pixels. But after uploading, it just uploads as a plain image without a border radius, but I want the image to be uploaded to have a border radius of 25 pixels. How could I accomplish this? Here's the code:

Javascript:

<script type="text/javascript">

const imgDiv = document.querySelector('.profile-pic-div');
const img = document.querySelector('#thePFP');
const file = document.querySelector('#file');

file.addEventListener('change', function(){
  // this refers to the file
  const choosedFile = this.files[0];

if (choosedFile) {
  const reader = new FileReader();

  reader.addEventListener('load', function(){
    img.setAttribute('src', reader.result);
  });

  reader.readAsDataURL(choosedFile);
}

});

</script>

HTML:

<img class="pfp" id="thePFP" src="img/pfp.png">

<div class="profile-pic-div">
  <img src="img/cam.png" class="camera" id="camera">
  <input type="file" class="file" id="file" accept="image/*" style="cursor: pointer">
</div>

PS. The image with the class of "pfp" is the default image I was talking about, when you login, that image with class "pfp" is the default image which I mentioned.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda