A Pen by hungryseashell on CodePen.
Created
March 9, 2023 12:24
-
-
Save hungryseashell/6bbfddc88a5703c5899325731449fe2d to your computer and use it in GitHub Desktop.
Croppie upload photo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| Ez egy 930x610-es képet vág ki a meseveled bannerhez. | |
| </div> | |
| <div class="container"> | |
| <div class="row"> | |
| <div class="col"> | |
| <form id="form1" runat="server"> | |
| <input type='file' id="imgInp" /> | |
| <img id="my-image" src="#" /> | |
| </form> | |
| <button id="use">Upload</button> | |
| <img id="result" src=""> | |
| </div> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function readURL(input) { | |
| if (input.files && input.files[0]) { | |
| var reader = new FileReader(); | |
| reader.onload = function(e) { | |
| $('#my-image').attr('src', e.target.result); | |
| var resize = new Croppie($('#my-image')[0], { | |
| viewport: { | |
| width: 930, | |
| height: 610, | |
| }, | |
| boundary: { | |
| width: 1000, | |
| height: 900, | |
| }, | |
| // showZoomer: false, | |
| // enableResize: true, | |
| enableOrientation: true | |
| }); | |
| $('#use').fadeIn(); | |
| $('#use').on('click', function() { | |
| resize.result('base64').then(function(dataImg) { | |
| var data = [{ image: dataImg }, { name: 'myimgage.jpg' }]; | |
| // use ajax to send data to php | |
| $('#result').attr('src', dataImg); | |
| // $('#imgInp').attr('value', dataImg); | |
| }) | |
| }) | |
| } | |
| reader.readAsDataURL(input.files[0]); | |
| } | |
| } | |
| $("#imgInp").change(function() { | |
| readURL(this); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .row { | |
| height: 100vh; | |
| } | |
| #my-image, #use { | |
| display: none; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" /> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css" rel="stylesheet" /> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment