var resizeableImage = function(image_target) {
// Some variable and settings
var $container,
orig_src = new Image(),
image_target = $(image_target).get(0),
event_state = {},
constrain = false,
min_width = 60, // Change as required
min_height = 60,
max_width = 1800, // Change as required
max_height = 1900,
init_height=500,
resize_canvas = document.createElement('canvas');
imageData=null;
init = function(){
//load a file with html5 file api
$('.js-loadfile').change(function(evt) {
var files = evt.target.files; // FileList object
var reader = new FileReader();
reader.onload = function(e) {
imageData=reader.result;
loadData();
}
reader.readAsDataURL(files[0]);
});
//add the reset evewnthandler
$('.js-reset').click(function() {
if(imageData)
loadData();
});
// When resizing, we will always use this copy of the original as the base
orig_src.src=image_target.src;
// Wrap the image with the container and add resize handles
$(image_target).height(init_height)
.wrap('<div class="resize-container"></div>')
.before('<span class="resize-handle resize-handle-nw"></span>')
.before('<span class="resize-handle resize-handle-ne"></span>')
.after('<span class="resize-handle resize-handle-se"></span>')
.after('<span class="resize-handle resize-handle-sw"></span>');
// Assign the container to a variable
$container = $('.resize-container');
//$container.style.width= "100px";
$container.prepend('<div class="resize-container-ontop"></div>');
// Add events
$container.on('mousedown touchstart', '.resize-handle', startResize);
$container.on('mousedown touchstart', '.resize-container-ontop', startMoving);
$('.js-crop').on('click', crop);
};
loadData = function() {
//set the image target
image_target.src=imageData;
orig_src.src=image_target.src;
$container.css("display", "inline-block");
//set the image tot he init...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.