Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:11:07+00:00 2026-05-26T08:11:07+00:00

I know there are thousands of jQuery plugins for image crop, but the one

  • 0

I know there are thousands of jQuery plugins for image crop, but the one I need is similar to Facebook’s image crop: a draggable fixed size square over a image, or a draggable image under a fixed size square.

I think there’s a simple elegant code for it, instead of a 10k-50k framework for image manipulation that I’m finding everywhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:11:08+00:00Added an answer on May 26, 2026 at 8:11 am

    I just built you a quick example of how to do it with jQuery: http://jsfiddle.net/gCqJ4/ It’s not too hard and you can build off of my example. License is MIT.

    There is a fundamental assumption being made here. First, your image is expected to already have been uploaded; this is just the crop part. Second, the image has a data-id attribute which specified the id of the image that the server can use.

    I’ll explain the JS a bit below:

    First part is your typical jQuery plugin declaration:

    (function($) {
        $.fn.croppable = function(settings) {
    

    Then we take an optional argument of settings, with some sane defaults (success being your anonymous function for handling successful data submissions):

            settings = settings || {
                square: 50,
                default: 'middle',
                id: $(this).data("id"),
                success: null
            };
    

    Next is just basic initial position calculation.

            var position = {
                x: settings.default == 'middle' ? ($(this).width() / 2) - (settings.square / 2) : 0 ,
                y: settings.default == 'middle' ? ($(this).height() / 2) - (settings.square / 2) : 0
            };
    

    We wrap the image in a container that can be styled and used as the parent containment for the draggable cropper.

            $(this).wrap("<div class='croppable-container' style='position: relative;' />");
    

    This is (obviously) the cropper.

            var cropper = $("<div style='position: absolute; top: " + position.y + "px; left: " + position.x + "px; height: " + settings.square + "px; width: " + settings.square + "px;' class='cropper' />");
    

    Place it before the image:

            $(this).before(cropper);
    

    Create a basic save button:

            var save = $("<input type='button' value='Crop Selection'/>");
    

    And bind it to a service to receive posts for the cropping:

            save.click(function () {
               $.post("/your/service/location",
                      {
                          img: id,
                          x: cropper.position().left,
                          y: cropper.position().top,
                          height: settings.square
                      },
                      function (data) {
                          if (settings.success != null) {
                              settings.success(data);
                          }
                      }
                );
            });
    
            $(this).parent().width($(this).width());
            $(this).parent().height($(this).height());
            cropper.draggable({containment: "parent"});
    
            $(this).parent().after(save);
    

    End of the typical plugin declaration:

        };
    })(jQuery);
    

    Call it:

    $(".croppable").croppable();
    

    As a final note, the plugin itself is only 1.61 KB. Small enough?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are thousands of examples on the internet, but I want for
i know there must be thousands of threads like this, but the internet and
I know there have been a lot of questions similar to my small problem.
I know there are plenty of other questions addressing the same problem, but since
I know there are plugins out there that allows you to style a select
I know there are multiple plugins out there however I wonder how I can
I know there should not be multiple publishers publishing the same event. But how
I know there is a registry key indicating the install directory, but I don't
I know there are a lot of positive things mod-rewrite accomplishes. But are there
I know there are thousands of tutorials on the topic however I don't get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.