After finding inspiration from a source I cannot name, I developed a plugin that allows for image cropping on both mobile and desktop devices.
The key features of my plugin include touch support, dynamic canvas sizing based on image dimensions, and the ability to move an image rather than just selecting an area. I initially considered purchasing a similar plugin but it did not meet my requirements when tested on different devices, prompting me to customize my own version.
You can view the working demo on JSFiddle.
This is the HTML structure:
<div class="container">
<canvas id="panel" width="779" height="519"></canvas>
</div>
<input type="button" value="crop Selection" id="crop-image" />
<img id="croppedSelection" height="100px" width="100px" />
To initialize the plugin:
var Cropper = new CanvasCrop(document.getElementById('panel'), 'http://www.script-tutorials.com/demos/197/images/image.jpg');
$('#crop-image').on('click', function(){
var src = Cropper.getBase64();
$('#croppedSelection').attr('src', src);
});
I am now facing a challenge - how can I ensure that the selection area remains visible on the screen even when the parent image is scrolled, similar to the functionality seen here.
Any help or advice on this matter would be greatly appreciated.
As the source code is too extensive to include here, you can refer to the JSFiddle for a full demonstration. Thank you.
Edit
An updated version of the demo with fixed canvas height and width issues can be found on JSFiddle.