jQuery Jcrop Plugin Last Updated : 13 Jul, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to crop an image using PHP and jQuery Jcrop plugin. Note: Please download the jQuery Jcrop plugin and include the required files in the head section of your HTML code. <link href=”jquery.Jcrop.min.css” rel=”stylesheet” type=”text/css”/> <script src=”jquery.min.js”></script> <script src=”jquery.Jcrop.min.js”></script> Example: The following HTML code demonstrates the Jcrop plugin by taking an image file and giving a "Crop Image" button to crop the image and show the output cropped image in another HTML "div". html <!DOCTYPE html> <html> <head> <!-- All the required libraries to crop the image--> <link rel="stylesheet" href="jquery.Jcrop.min.css" type="text/css" /> <script src="jquery.min.js"></script> <script src="jquery.Jcrop.min.js"></script> <style> body { width: 500px; height: 380px; font-family: Arial, Sans-serif; } .btnSubmitClass { background-color: #696969; padding: 5px 30px; border: #696969 1px solid; border-radius: 4px; color: #FFFFFF; margin-top: 10px; } input#cropBtnID { padding: 5px 25px 5px 25px; background: #D3D3D3; border: #98b398 1px solid; color: #FFF; visibility: hidden; } #outputImage { margin-top: 40px; } </style> </head> <body> <h2> How to crop image using jQuery and PHP </h2> <div> <img src="gfg2.jpg" id="cropImageID" class="img" /><br /> </div> <div id="btn"> <input type='button' id="cropBtnID" value='Crop Image'> </div> <div> <img src="#" id="outputImage" style="display:none;"> </div> <script type="text/javascript"> $(document).ready(function () { let size; $('#cropImageID').Jcrop({ /* Some settings for basic configuration*/ allowSelect: true, allowMove: true, allowResize: true, fixedSupport: true, aspectRatio: 1, onSelect: function (c) { size = { x: c.x, y: c.y, w: c.w, h: c.h }; $("#cropBtnID").css( "visibility", "visible"); }//end onSelect });//end Jcrop method $("#cropBtnID").click(function () { let img = $("#cropImageID").attr('src'); $("#outputImage").show(); $("#outputImage").attr('src', 'image-features.php?x = ' + size.x + ' & y=' + size.y + ' & w=' + size.w + '&h=' + size.h + '&img=' + img); }); });//end document ready fn </script> </body> </html> PHP code: The following PHP code implements the "image-features.php" file that is used in the above HTML code for image and color creation. The PHP function used for creating a new image is imagecreatefromjpeg() method. A new true color image is created using PHP imagecreatetruecolor() method. Other PHP functions used are imagecopyresampled() and imagejpeg(). php <?php // Create a new image from a file $newImage = imagecreatefromjpeg($_GET['img']); // Create a new true color image $newTruecolorImage = imagecreatetruecolor( $_GET['w'], $_GET['h']); // Copy a portion from one image to another imagecopyresampled($newTruecolorImage, $newImage, 0, 0, $_GET['x'], $_GET['y'], $_GET['w'], $_GET['h'], $_GET['w'], $_GET['h']); header('Content-type: image/jpeg'); // Display image to browser as output imagejpeg($newTruecolorImage); exit; ?> Output: Comment More infoAdvertise with us Next Article jQuery Jcrop Plugin G geetanjali16 Follow Improve Article Tags : Web Technologies PHP HTML CSS JQuery jQuery-Plugin +2 More Similar Reads jQuery Page Piling Plugin jQuery pagePiling.js plug-in is a rich feature available for programmers for piling more than one layout section, one over the other, and accessing each page by URL or mouse scrolling or side bullets navigation. This feature provides all type of smooth vertical, horizontal, and side navigations to t 5 min read jQuery | Flickerplate Plugin jQuery provides Flickerplate plugin that helps our programmers to create sliders for websites that can cycle through a list of background images along with dot navigation feature and animated arrows. The plugin consists of many more libraries that are responsible for touch detections and events such 5 min read jQuery Multiscroll Plugin jQuery provides multiscroll.js plugin which helps programmers to create split web pages along with divided multiple vertical scrolling panels.Note: Please download the jQuery multiscroll plugin to your working folder and include the required files in the head section of your code as shown below. Dow 3 min read jQuery RowGrid Plugin jQuery provides a very simple, user-friendly and responsive rowGrid plugin that helps programmers to display images in a straight row. It is very lightweighted and supports infinite scrolling feature. Real examples of rowGrid are Google+ images or Google image search that appears in a straight row g 4 min read jQuery Alertify Plugin jQuery framework provides alertify.js plugin that provides pre-designed customizable notification system along with interactive browser dialogs. This extensible and themeable plugin is very useful for developers providing an optimized version of alert messages with stacking up to feature. This small 5 min read jQuery Image ProgressBars Plugin In this article, we will learn how to implement image ProgressBar feature using the jQuery Image ProgressBar plugin. Note: Please download the jQuery Image ProgressBar plugin in the working folder and include the required files in the head section of your HTML code. <link href=âprogressbar.cssâ r 2 min read jQuery DrawSVG Plugin SVG or Scalar Vector Graphics is Extended Markup Language-based graphics supporting 2 dimensional animations of images enhancing interactiveness. The specifications of SVG are open standards by World Wide Web Consortium defined in XML text files. These files can be changed or created with any drawin 4 min read jQuery Tagsort Plugin jQuery provides Tagsort plugin that is used for displaying tags or filter elements based on different tags in a DOM. The plugin takes data-attributes of HTML page structure and dynamically creates user-friendly tags used for filtering elements. The filtration of elements are done in many ways that a 9 min read jQuery Logos Distort Plugin The jQuery provides LogosDistort plugin which helps in creating or animating a parallax environment for 3D scenes in the user browser. It uses full-page matrix3D perspective logos distortions for transforming base on mouse movement. You have to download the required files in the working folder so th 4 min read jQuery Filer Plugin jQuery provides a quick jQuery Filer uploader plugin for easy implementation of uploading the files. It provides features like instant uploading of files, file append, file removal, multiple selections, drag and drop support along with other file validations.Download the required files to include it 2 min read Like