Open Source Image Uploader created with jquery. Build over Cropper Library.
Include Jquery, Croppie and ImgUploader library to HTML inside Footer if using Bootstrap modal then ensure that bootstrap and it’s JavaScript file are include in template.
<script src="image_uploader/croppie.min.js"></script>
<script src="image_uploader/img.uploader.min.js"></script>
Including Croppie CSS to HTML inside <head>
<link href="image_uploader/croppie.css" rel="stylesheet">
This class is applied to <input> which triggers ImgUploader Library after image file is choosen.
This class is applied to empty container <div> which will act as Image Editor Canvas.
This class is applied to button which will upload image using ajax when it is clicked.
This class is applied to button which cancels upload operation and clear file input. It is mandatory to use this class in editor to destroy all editor instances on button click.
This class is applied to button which will rotate Image to left.
This class is applied to button which will rotate Image to right.
This class is applied to button which will clear all the filters applied to image.
<input> with class .img-upload-input can use following parameters
This parameter pass id of Image Uploader Menu which appear to the user after the image has been selected
This parameter pass url where image data has to be send via ajax.
defines size of cropped image. Valid values are *“viewport”, *“original” or *"{width,height}". viewport will make image size as size of canvas viewport and original will only crop and retain original size.
This parameter pass type of cropper to be used to crop image. Valid values are *“circle” and *“square”. Default is *“square” if parameter is not passed.
define width of editor viewport. Default value is 300
define width of editor viewport. Default value is 300
pshape=“square”,w=300,h=100,size=“original”
This parameter pass id of Image which display new uploaded image.
This parameter pass id of empty container which will display upload status send by server.
To apply filter to Uploaded Image create a input range or a button which will apply filter to image and assign *“class filter” with filter type to *“filter” attribute. Input type choosen depends on type of filter.
Currently following filters are applied to image:
Increases/Decrease Brightness level of a Image. * “Range Input”
<label>Brightness</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="brightness"/>
Make Brighter area white and darker area black depending on threshold value. * “Range Input”
<label>Threshold</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="threshold"/>
Turns Image into grayscale. * “Single Input”
<button type="button" class="btn btn-dark filter" filter="grayscale">Grayscale</button>
Sharp Edges in Image. * “Single Input”
<button type="button" class="btn btn-dark filter" filter="sharpen">Sharpen</button>
Smooth out sharp edges in image. * “Single Input”
<button type="button" class="btn btn-dark filter" filter="blur">Blur</button>
This menu will appear to the user after the image has been selected. The menu creation is customizable and its design depends on the developer. The menu can also be in the form of a Modal. in this example, bootstrap modal is used.
<!-- Using Bootstrap Modal -->
<div class="modal fade" id="img-upload-panel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Upload Profile Photo</h4>
<button type="button" class="img-remove-btn-bs close">×</button>
</div>
<div class="modal-body">
<div class="row container">
<div class="col">
<div class="img-edit-container"></div>
</div>
</div>
<div class="row container">
<div class="col">
<label>Brightness</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="brightness"/>
</div>
<div class="col">
<label>Threshold</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="threshold"/>
</div>
</div>
<div class="row container">
<div class="col">
<button type="button" class="btn btn-dark filter" filter="grayscale">Grayscale</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark filter" filter="sharpen">Sharpen</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark filter" filter="blur">Blur</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-clear-filter">Clear</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-rotate-left">Rotate Left</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-rotate-right">Rotate Right</button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary img-remove-btn-bs">Close</button>
<button type="button" class="btn btn-primary img-upload-btn-bs">Upload</button>
</div>
</div>
</div>
</div>
<div class="container" id="img-upload-panel">
<h4 class="modal-title">Upload Photo</h4>
<div class="row">
<div class="col">
<div class="img-edit-container"></div>
</div>
</div>
<div class="row container">
<div class="col">
<label>Brightness</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="brightness"/>
</div>
<div class="col">
<label>Threshold</label>
<input type="range" class="form-control-range filter" min=0 max=200 value=100 step=1 filter="threshold"/>
</div>
</div>
<div class="row container">
<div class="col">
<button type="button" class="btn btn-dark filter" filter="grayscale">Grayscale</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark filter" filter="sharpen">Sharpen</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark filter" filter="blur">Blur</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-clear-filter">Clear</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-rotate-left">Rotate Left</button>
</div>
<div class="col">
<button type="button" class="btn btn-dark img-rotate-right">Rotate Right</button>
</div>
</div>
<div class="container">
<button type="button" class="btn btn-secondary img-remove-btn">Clear</button>
<button type="button" class="btn btn-primary img-upload-btn">Upload</button>
</div>
</div>
<input type=file class="img-upload-input" editor="#img-upload-panel" target="#profile-img" status="#status" passurl="/profile-img-process" pshape="circle" w=200 h=200 size="viewport"/>
<input type=file class="img-upload-input" editor="#img-upload-panel" target="#image" status="#status" passurl="" pshape="square" w=300 h=150 size="{1920,480}"/>
The backbone of this plugin is Cropper Library so all credit goes to it.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.