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 8522557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:09:20+00:00 2026-06-11T07:09:20+00:00

I am using Jcrop to allow my users to crop an image before loading

  • 0

I am using Jcrop to allow my users to crop an image before loading it into the next form. I load a stack of images in a JS array from the DB so they can scroll through images quickly.

When i load a new image into JCrop it screws up the aspect ratio. Below is my js

<script type="text/javascript">

    jQuery(function($){

      // Create variables (in this scope) to hold the API and image size
      var jcrop_api, boundx, boundy;

      $('#fbimage').Jcrop({
        onChange: updatePreview,
        onSelect: updatePreview,
        aspectRatio: 1
      },function(){
        // Use the API to get the real image size
        var bounds = this.getBounds();
        boundx = bounds[0];
        boundy = bounds[1];
        //Store the API in the jcrop_api variable
        jcrop_api = this;
      });

        $('#nextPhoto').click(function(e) {
            if ($('.prevPhoto:hidden'))
            {
                $('#prevPhoto').show();
            }
            count= parseFloat($('#profilePicCOUNT').val());
            count = count+1;
            $('#profilePicCOUNT').val(count);
            //$('.fbimage').attr("src",images[count-1]);
            $('.previewpic').attr("src",images[count-1]);
            jcrop_api.setImage(images[count-1]);
            jcrop_api.setOptions({ bgOpacity: .6 });


            $('#profilePicURL').val(images[count-1]);
            if (count==images.length )
            {
                $('#nextPhoto').hide();
            }
              return false;
        });

        $('#prevPhoto').click(function(e) {
            if ($('#profilePicCOUNT').val()==2)
            {
                $('#prevPhoto').hide();
            }
            if (count<(images.length+1) )
            {
                $('#nextPhoto').show();
            }
            count= parseFloat($('#profilePicCOUNT').val());
            count = count-1;
            $('#profilePicCOUNT').val(count);
            //$('.fbimage').attr("src",images[count-1]);
            $('.previewpic').attr("src",images[count-1]);
            jcrop_api.setImage(images[count-1]);
            jcrop_api.setOptions({ bgOpacity: .6 });
            $('#profilePicURL').val(images[count-1]);
            count= parseFloat($('#profilePicCOUNT').val());
            count = count-1;
            return false;
        });

      function updatePreview(c)
      {
        if (parseInt(c.w) > 0)
        {
          var rx = 100 / c.w;
          var ry = 100 / c.h;

          $('#previewpic').css({
            width: Math.round(rx * boundx) + 'px',
            height: Math.round(ry * boundy) + 'px',
            marginLeft: '-' + Math.round(rx * c.x) + 'px',
            marginTop: '-' + Math.round(ry * c.y) + 'px'
          });
        }
      };

    });

</script>
  • 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-06-11T07:09:22+00:00Added an answer on June 11, 2026 at 7:09 am

    After several hours searching and trying the answer was simple. This line of code resets the preview ratio to work nicely:

    var newUrl = 'https://..../image.jpg'
    var jcrop_api = $('#Image1').data("Jcrop");
    jcrop_api.setImage(newUrl , function() {
        jcrop_api = this;
        var bounds = this.getBounds();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jcrop to crop the image in my php application.I am using
I want to crop an image at the server side (I am using 'JCrop'
I am trying to crop the image using JQuery Jcrop plugin with Java Stuff,
I am using JCrop plugin to crop image, things are working good with following
I am using jcrop to implement image cropping in my site. After clicking on
I'm using jcrop to crop my photos and need to send the current values
I'm trying to develop image crop using JQuery. I use ajax to upload the
I am using Jquery form plugin. Popup is displayed with image uploading form. Image
I'm using the latest version of jquery.jcrop. When invoking jcrop() on an image, the
I am using Jcrop on an image that is resized with css for uniformity.

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.