I've been scouring the internet in search of a solution to my problem, but it seems like I might not be looking in the right places.
Imagine this image below, how can I replace the blue area with an image uploaded by the user? I'm struggling to figure out how to achieve this.
I stumbled upon this which talks about drawing a red rectangle based on specific coordinates, but what I need (I believe) is to identify those coordinates and swap them out with an image. Has anyone encountered this before? Any guidance would be greatly appreciated as I'm stuck here!
https://i.sstatic.net/rrGp5.jpg
Please note that the image used here is just for illustrative purposes and does not belong to me. Thank you for your help.
EDIT:
I realize I should have included the code initially, apologies for that oversight. This project is built using phonegap and jquery mobile, with a navbar at the bottom. One of the pages, named "preview," requires the functionality to change images, but I seem to be missing something due to lack of knowledge:
My index.html:
<div data-role="page" data-url="preview" id="preview">
<div data-role="header" style="background-color: rgb(182, 202, 51)" data-position="fixed">
<h1 id="titlePreview">PREVIEW</h1>
<a href="#language" id="langBtn" style="width: 20px;height: 20px; background:none; " href="#" data-icon="comment" data-iconpos="notext" class="ui-btn-left"></a>
</div>
<div id="previewSaco" class="containerPreviewSaco">//if i remove this div, the navbar on the bottom disapears.
<canvas id="myCanvas" width="200" height="200">//i´m testing with this size, but yes the image is supose to have a 100% with, in fact the image as 1940x2372.
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar" class="ui-bar">
<ul>
//in here i have my several "li" for navegation and i think it´s irrelevant for my question.
</ul>
</div>
</div>
</div>
My .js file:
$(document).on("click", "#btnPreview", function (event) {
var ctx = document.getElementById('myCanvas').getContext('2d');
var img = new Image;
img.onload = function(){
ctx.drawImage(img,0,0);
img2.src = 'img/capa.png';
};
var img2 = new Image;
img2.onload = function(){
ctx.globalCompositeOperation = 'destination-over';
//ctx.scale(x, y);
//ctx.rotate(angle);
//ctx.translate(x, y);
//or
//ctx.transform(a, b, c, d, e, f);
ctx.drawImage(img2,0,0);
};
var uri1 = 'img/previewSaco1.png'; //the main image supposed to load on page click "preview", **but it's not happening** also featuring a transparent area for user-uploaded images.
var uri2 = 'img/capa.png';//a dummy logo image for larger image testing
img.src = uri1;
});
Note: when running the app, the phonegap desktop constantly displays: undefined Content Security Policy has been modified to be: https://ssl.gstatic.com;style-src 'self' 'unsafe-inline' data: blob:;media-src *;img-src * 'self' data: content:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">