How to crop an image in the shape of a circle, and then set it inside another image?

I'm working on a pet search application, and I need to crop my pet's avatar into a small circle that will later be β€œmerged” / merged with the outline, and then passed as a marker to google static maps. I want to do this in the interface, because to do this on the back-end it will be required (if the service will expand or increase too much), some more space management for images will be required.

This is the outline: Profile outline

The result should look like this: enter image description here

The profile image can be of any size larger than the outline, so they will have any shape (usually square or rectangular).

I am trying to figure out if I can do this completely on the interface. As far as I know, I can:

  • Take a profile picture and paste it into the canvas
  • Then we cut it in a circular shape (I don’t know how to do it)
  • Convert it back to image (not sure if this is necessary)
  • Add it to another canvas so that I can combine it with the outline
  • Save it as an image, and then send it to static Google maps as a marker

I thought that if I made the borders of the canvas round (with a border radius of css), it could work, but it is not.

So, for the question itself, is it possible to crop the image into a circle only using JavaScript and Canvas (in the interface), or should I do this in the background? And if possible, then how?

Thanks in advance.

+2
javascript image google-maps canvas crop
source share

No one has answered this question yet.

See similar questions:

8
JS Maps v3: User Token with User Profile Image
4
How to get rotated cropping an image with HTML5 canvas

or similar:

7728
How to redirect to another web page?
4829
How to include a javascript file in another javascript file?
1623
How to check if the string "StartsWith" contains another string?
1599
How to move an element to another element?
1338
How to vertically align an image inside a div
1264
How can I automatically resize the image to fit the div container?
1204
How to access the correct `this` inside a callback?
78
The radius of the draw around the point in the Google map
3
Cropping images with non-rectangular html5 canvas and transform
0
SVG Circle: circular image

All Articles