crop.blade.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. @extends('layouts.admin')
  2. @section('title')
  3. News - Inserimento immagine
  4. @stop
  5. @section('content')
  6. <div class="row">
  7. <div class="col-lg-12">
  8. <input type="file" id="upload" value="Choose a file" class="btn btn-info" accept="image/x-png,image/jpeg"><br>
  9. <div id="upload-h"></div>
  10. <div id="upload-v"></div>
  11. <a href="#" class="upload-result btn btn-success">Procedi</a>
  12. <form action="/admin/news/crop" id="form" method="POST">
  13. {{ csrf_field() }}
  14. <input type="hidden" name="imagebase64H" id="imagebase64H">
  15. <input type="hidden" name="imagebase64V" id="imagebase64V">
  16. <input type="hidden" name="news_id" id="news_id" value="{{isset($_GET['news_id']) ? $_GET['news_id'] : ''}}">
  17. </form>
  18. </div>
  19. </div>
  20. @stop
  21. @section('extra_css')
  22. <link rel="stylesheet" href="/css/croppie.css" />
  23. <style>
  24. .cr-image
  25. {
  26. display:none;
  27. }
  28. </style>
  29. @stop
  30. @section('extra_js')
  31. <script src="/js/croppie.js"></script>
  32. <script>
  33. $( document ).ready(function() {
  34. var $uploadCropV;
  35. var $uploadCropH;
  36. /*$("input[name='orientation']").click(function() {
  37. if ($(this).val() === 'vertical') {
  38. document.location.href = '/admin/news/crop?vertical=1';
  39. } else if ($(this).val() === 'horizontal') {
  40. document.location.href = '/admin/news/crop';
  41. }
  42. });*/
  43. $("#upload").change(function(){
  44. setTimeout(function(){ $(".cr-image").show(); }, 500);
  45. });
  46. function readFile(input) {
  47. if (input.files && input.files[0]) {
  48. var reader = new FileReader();
  49. reader.onload = function (e) {
  50. $uploadCropV.croppie('bind', {
  51. url: e.target.result
  52. }).then(function(){
  53. $('.cr-slider').attr({'min':0.5000, 'max':3.5000});
  54. });
  55. $('.upload-v').addClass('ready');
  56. $uploadCropH.croppie('bind', {
  57. url: e.target.result
  58. }).then(function(){
  59. $('.cr-slider').attr({'min':0.5000, 'max':3.5000});
  60. });
  61. $('.upload-h').addClass('ready');
  62. }
  63. reader.readAsDataURL(input.files[0]);
  64. }
  65. }
  66. $uploadCropV = $('#upload-v').croppie({
  67. viewport: {
  68. width: 400,
  69. height: 650,
  70. type: 'rectangle'
  71. },
  72. boundary: {
  73. width: 500,
  74. height: 750
  75. }
  76. });
  77. $uploadCropH = $('#upload-h').croppie({
  78. viewport: {
  79. width: 550,
  80. height: 400,
  81. type: 'rectangle'
  82. },
  83. boundary: {
  84. width: 750,
  85. height: 500
  86. }
  87. });
  88. $('#upload').on('change', function () { readFile(this); });
  89. $('.upload-result').on('click', function (ev) {
  90. $uploadCropH.croppie('result', {
  91. type: 'canvas',
  92. size: 'viewport'
  93. }).then(function (resp) {
  94. $('#imagebase64H').val(resp);
  95. });
  96. $uploadCropV.croppie('result', {
  97. type: 'canvas',
  98. size: 'viewport'
  99. }).then(function (resp) {
  100. $('#imagebase64V').val(resp);
  101. });
  102. setTimeout(function(){ $('#form').submit(); }, 3000);
  103. });
  104. });
  105. /*
  106. function zoomin(ev) {
  107. targetZoom = self._currentZoom + 0.005;
  108. ev.preventDefault();
  109. _setZoomerVal.call(self, targetZoom);
  110. change.call(self);
  111. }
  112. function zoomout(ev) {
  113. targetZoom = self._currentZoom - 0.005;
  114. ev.preventDefault();
  115. _setZoomerVal.call(self, targetZoom);
  116. change.call(self);
  117. }
  118. */
  119. </script>
  120. @stop