I've been bored recently and wrote a practical code. AngularJS implements avatar intercepting through ng-Img-Crop and share it with everyone
1. Install the plug-in
bower install ngImgCrop
2. Introduce plug-ins
<script src=""></script> <link rel="stylesheet" type="text/css" href="" rel="external nofollow" rel="external nofollow" >
3. Add dependencies
var app = ('myApp', ['ngImgCrop']);
4. Usage
<img-crop image="myImage" result-image="myCroppedImage"></img-crop>
5. Parameters
<img-crop image="{string}" //The image variable name that needs to be intercepted result-image="{string}" //The variable name assigned after intercepting [change-on-fly="{boolean}"] // Whether to update the preview of the user's image intercepted in real time? If not, the preview image will be updated after the user stops the action. [area-type="{circle|square}"] //Seave the shape of the image frame (circle or square) [area-min-size="{number}"] //The minimum area of the clipping image frame [result-image-size="{number}"] //The size of the image after the clipping [result-image-format="{string}"] //The format of the image after the intercept [result-image-quality="{number}"] //The quality of the image after the intercept [on-change="{expression}"] [on-load-begin="{expression"] [on-load-done="{expression"] [on-load-error="{expression"] ></img-crop>
<html> <head> <script src=""></script> <script src=""></script> <link rel="stylesheet" type="text/css" href="" rel="external nofollow" rel="external nofollow" > <style> .cropArea { background: #E4E4E4; overflow: hidden; width:500px; height:350px; } </style> <script> ('app', ['ngImgCrop']) .controller('Ctrl', function($scope) { $=''; $=''; var handleFileSelect=function(evt) { var file=[0]; var reader = new FileReader(); = function (evt) { $scope.$apply(function($scope){ $=; }); }; (file); }; (('#fileInput')).on('change',handleFileSelect); }); </script> </head> <body ng-app="app" ng-controller="Ctrl"> <div>Select an image file: <input type="file" /></div> <div class="cropArea"> <img-crop image="myImage" result-image="myCroppedImage"></img-crop> <!-- Snap the picture frame --> </div> <div>Cropped Image:</div> <div><img ng-src="{{myCroppedImage}}" /></div> <!-- Preview picture frame --> </body> </html>
7. Official Documentation
/alexk111/ngImgCrop
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.