I'm trying to build a little tool that enables me to take an image, put a PNG transparent mask over it, then scale and drag the image in place to get it perfectly positioned/sized within the mask.
Here is the jquery.
$(window).load(function(){
var globalElement_width;
var globalElement_height;
$(document).ready(function(){
$img=$('.canvas img');
globalElement_width=$img.width();
globalElement_height=$img.height();
$( ".slider" ).slider({
step: 1,
min: 0,
max: 100,
value: 0,
slide: function( event, ui )
{
resize_img(ui.value);
}
});
$('.canvas img').draggable();
});
function resize_img(val) {
var width=globalElement_width;
var zoom_percen=width * 0.5; // Maximum zoom 50%
var ASPECT = zoom_percen / 50;
var zoom_value = val / 2;
var size= width + ASPECT * zoom_value;
$img = $('.canvas img');
$img.stop(true).animate({
width: size
}, 1);
}
});
I have 2 issues (in addition to the code probably being pretty janky)
I want the image to initially load behind the mask at actual size centered and have the slider allow for scaling smaller, not larger as I have it now. I want to ensure the image never goes above it's actual dimension to avoid distortion. The slider should slide to the left, representing decrease in size, not to the right as it does.
Once i get the placement right, i want to be able to click a button and then output the new HTML/CSS/JS for the newly resized and positioned graphic. Then I can just take this code and put it into a site and show the image and mask without any UX to resize/position/etc. Just hard coded in that exact state I generated.
Any help is greatly appreciated... this is as far as I can get cobbling various pieces of code together. Also, suggestions on cleanup of what I have is encouraged.
Thanks!