php - Change image size on click of button in jQuery -


i working on image upload , need add functionality image shapes.

there buttons landscape, portrait, square , panoramic. when user clicks of these, div shape change accordingly.

this code square shape when click on square shape, stretches image. want change shape of div without stretching image.

$('#square').on('click', function(){     var images = $("#uploadedimage");     for(i=0; i<images.length; i++)         images[i].onload = centerimage(images[i]);      function centerimage(img) {         if (img.width > img.height ) {             var y = 160;             var x = img.width/img.height*y;             var marx = (x-y)/2;             img.style.height = y+"px";             img.style.marginleft = -(marx) + "px";         }     } }); 

it's difficult recreate running example without more generalized code, function changes dimensions of variable img, image passed in function, , not div or other element besides image clicked. if want change div based on same hxw test of image, change img.* parts of function $('#divyouwant').* , should on right track. along lines of:

 function centerimage(img) {         if (img.width > img.height ) {             var y = 160;             var x = img.width/img.height*y;             var marx = (x-y)/2;             $('#divyouwannamod').height = y+"px";             $('#divyouwannamod').marginleft = -(marx) + "px";         }     } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -