code_junkie

javascript Image Resize

Nov 11th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. image.style.width = '50%'
  2. image.style.height = 'auto'
  3.  
  4. if($(this).width() > $(this).height()) {
  5. $(this).css('width',MaxPreviewDimension+'px');
  6. $(this).css('height','auto');
  7. } else {
  8. $(this).css('height',MaxPreviewDimension+'px');
  9. $(this).css('width','auto');
  10. }
  11.  
  12. myimg = document.getElementById('myimg');
  13. myimg.style.height = "50px";
  14. myimg.style.width = "50px";
  15.  
  16. myimg = document.getElementById('myimg');
  17. myimg.height = myimg.height * 2;
  18. myimg.width = myimg.width * 2;
  19.  
  20. function Resize(imgId)
  21. {
  22. var img = document.getElementById(imgId);
  23. var w = img.width, h = img.height;
  24. w /= 2; h /= 2;
  25. img.width = w; img.height = h;
  26. }
  27.  
  28. function resize_image(image, w, h) {
  29.  
  30. if (typeof(image) != 'object') image = document.getElementById(image);
  31.  
  32. if (w == null || w == undefined)
  33. w = (h / image.clientHeight) * image.clientWidth;
  34.  
  35. if (h == null || h == undefined)
  36. h = (w / image.clientWidth) * image.clientHeight;
  37.  
  38. image.style['height'] = h + 'px';
  39. image.style['width'] = w + 'px';
  40. return;
  41. }
  42.  
  43. var scale=0.5;
  44.  
  45. minWidth=50;
  46. minHeight=100;
  47.  
  48. if($("#id img").width()*scale>minWidth && $("#id img").height()*scale >minHeight)
  49. {
  50. $("#id img").width($("#id img").width()*scale);
  51. $("#id img").height($("#id img").height()*scale);
  52. }
Add Comment
Please, Sign In to add comment