lib_photosresize.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2009-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. // or see https://www.gnu.org/
  16. //
  17. // \file htdocs/lib/lib_photoresize.js
  18. // \brief File that include javascript functions for croping feature
  19. //
  20. /* Enable jcrop plugin onto id cropbox */
  21. jQuery(function() {
  22. jQuery('#cropbox').Jcrop({
  23. onSelect: updateCoords,
  24. onChange: updateCoords
  25. });
  26. });
  27. /* Update fields that store new size */
  28. function updateCoords(c)
  29. {
  30. //alert(parseInt(jQuery("#ratioforcrop").val()));
  31. ratio=1;
  32. imagewidth=0;
  33. imageheight=0;
  34. console.log(c);
  35. if (parseInt(jQuery("#ratioforcrop").val()) > 1) {
  36. ratio = parseInt(jQuery("#ratioforcrop").val());
  37. if (parseInt(jQuery("#imagewidth").val()) > 0) imagewidth = parseInt(jQuery("#imagewidth").val());
  38. if (parseInt(jQuery("#imageheight").val()) > 0) imageheight = parseInt(jQuery("#imageheight").val());
  39. }
  40. x = Math.floor(c.x * ratio);
  41. y = Math.floor(c.y * ratio);
  42. x2 = Math.ceil(c.x2 * ratio);
  43. y2 = Math.ceil(c.y2 * ratio);
  44. console.log("x="+x+" y="+y+" x2="+x2+" y2="+y2+" imageheight="+imageheight+" ratio="+ratio);
  45. if (imagewidth > 0 && x > imagewidth) {
  46. x = imagewidth;
  47. }
  48. if (imageheight > 0 && y > imageheight) {
  49. y = imageheight;
  50. }
  51. if (imagewidth > 0 && x2 > imagewidth) {
  52. x2 = imagewidth;
  53. }
  54. if (imageheight > 0 && y2 > imageheight) {
  55. y2 = imageheight;
  56. }
  57. //console.log(ratio);
  58. jQuery('#x').val(x);
  59. jQuery('#y').val(y);
  60. jQuery('#x2').val(x2);
  61. jQuery('#y2').val(y2);
  62. jQuery('#w').val(x2-x);
  63. jQuery('#h').val(y2-y);
  64. };