|
6 | 6 | @using (Html.AjaxBeginFormModal("Index", "UploadImage")) |
7 | 7 | { |
8 | 8 | @Html.AntiForgeryToken() |
9 | | - <div class="modal-dialog" role="document" > |
| 9 | + <div class="modal-dialog" role="document"> |
10 | 10 | <div class="modal-content"> |
11 | 11 | <div class="modal-header"> |
12 | 12 | <h5 class="modal-title">Example Modal</h5> |
|
18 | 18 | @Html.HiddenFor(m => m.Width) |
19 | 19 | @Html.HiddenFor(m => m.Height) |
20 | 20 | @Html.HiddenFor(m => m.ImageBase64) |
21 | | - <div id="uploadImageContainer" > |
| 21 | + <div id="uploadImageContainer"> |
22 | 22 | </div> |
23 | 23 | <div class="d-flex flex-row gap-1"> |
24 | | - <input id="ImageFile" type="file" class="form-control w-100" /> |
| 24 | + <input id="ImageFile" name="ImageFile" type="file" class="form-control w-100" /> |
25 | 25 | <button id="btn-crop" type="button" class="btn btn-info w-50" disabled>Crop Image</button> |
26 | 26 | </div> |
27 | 27 | @Html.ValidationMessageFor(m => m.ImageBase64, "", new { @class = "text-danger" }) |
|
36 | 36 | var uploadImageHeight = +$('#Height').val(); |
37 | 37 | var uploadImageInput = $('#ImageFile'); |
38 | 38 | var uploadImageContainer = $('#uploadImageContainer'); |
39 | | - var scaleFactor = uploadImageHeight >= 512 || uploadImageWidth >= 512 ? 0.8 : 1; |
| 39 | + var uploadScaleFactor = scaleFactor(uploadImageHeight); |
40 | 40 |
|
41 | 41 | var croppie = uploadImageContainer.croppie({ |
42 | 42 | url: '/images/placeholder.jpg', |
43 | 43 | viewport: { |
44 | | - width: uploadImageWidth * scaleFactor, // Set your desired width |
45 | | - height: uploadImageHeight * scaleFactor, // Set your desired height |
46 | | - type: 'square' // You can use 'square', 'circle', or 'rectangle' |
| 44 | + width: uploadImageWidth * uploadScaleFactor, |
| 45 | + height: uploadImageHeight * uploadScaleFactor, |
| 46 | + type: uploadImageWidth == uploadImageHeight ? 'square' : 'rectangle' |
47 | 47 | }, |
48 | 48 | boundary: { |
49 | | - width: (uploadImageWidth + 50) * scaleFactor, // Set the width of the boundary container |
50 | | - height: (uploadImageHeight + 50) * scaleFactor // Set the height of the boundary container |
| 49 | + width: (uploadImageWidth + 50) * uploadScaleFactor, |
| 50 | + height: (uploadImageHeight + 50) * uploadScaleFactor |
51 | 51 | } |
52 | 52 | }); |
53 | 53 |
|
54 | | -
|
55 | 54 | uploadImageInput.on('change', function (e) { |
56 | 55 | $('#btn-crop, #submit').attr('disabled', 'disabled'); |
57 | 56 | const files = e.target.files; |
58 | 57 | if (files.length > 0) { |
59 | 58 | const reader = new FileReader(); |
60 | 59 | reader.onload = function (e) { |
61 | | - // Set the image source for Croppie |
62 | 60 | croppie.croppie('bind', { |
63 | 61 | url: e.target.result |
64 | 62 | }); |
|
74 | 72 | $('#submit').removeAttr('disabled'); |
75 | 73 | }); |
76 | 74 | }); |
77 | | -
|
78 | 75 | </script> |
79 | 76 | </div> |
80 | 77 | } |
|
0 commit comments