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

  • SEARCH
  • Home
  • 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 6563739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:53:05+00:00 2026-05-25T13:53:05+00:00

I am using Jcrop with a preview pane as seen in the tutorial here

  • 0

I am using Jcrop with a preview pane as seen in the tutorial here http://net.tutsplus.com/articles/news/working-with-the-jcrop-plugin/. This shows how to create a simple Jcrop interface with a preview pane to show the result as you crop. Unfortunately the preview pane in this case is of a fixed size and simply zooms the image in and out as you crop, producing a cropped image of that same fixed size.

What I’d like to do is have the preview pane resize along with the crop tool to display the resulting image as the user crops, allowing the user to decide the dimensions of the resulting image. I can then apply a max or min size when the image is uploaded.

The preview pane CSS and the code are below. Note the targ_h and targ_w variables are defined to whatever I choose. The orig_w and orig_h are read from the original image.

    #preview
    {
        width: <?php echo $targ_w?>px;
        height: <?php echo $targ_h?>px;
        overflow:hidden;
    }



function updateCoords(c)
        {
            showPreview(c);
            $("#x").val(c.x);
            $("#y").val(c.y);
            $("#w").val(c.w);
            $("#h").val(c.h);
        }

        function showPreview(coords)
        {
            var rx = <?php echo $targ_w;?> / coords.w;
            var ry = <?php echo $targ_h;?> / coords.h;

            $("#preview img").css({
                width: Math.round(rx*<?php echo $orig_w;?>)+'px',
                height: Math.round(ry*<?php echo $orig_h;?>)+'px',
                marginLeft:'-'+  Math.round(rx*coords.x)+'px',
                marginTop: '-'+ Math.round(ry*coords.y)+'px'
            });
        }

Has anyone done this before and had the width and height of the preview pane change with the width and height of the crop tool?

  • 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-25T13:53:05+00:00Added an answer on May 25, 2026 at 1:53 pm

    This is what I did in mine:

    function showPreview(photoDiv, coords, maxX, maxY)
    {
        var rx = maxX / coords.w;
        var ry = maxY / coords.h;
    
        rx = (rx == 0) ? 1 : rx;
        ry = (ry == 0) ? 1 : ry;
    
        photoX = $("#" + photoDiv + " #photo").width();
        photoY = $("#" + photoDiv + " #photo").height();
    
        $("#" + photoDiv + " #preview").css({
            width: Math.round(rx * photoX) + 'px',
            height: Math.round(ry * photoY) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
    }
    

    I guess maxX will refer to your $targ_w. This is setup this way because I have multiple jCrop instances in one page. Edit it depending on your setup.

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

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Im using jCrop http://deepliquid.com/content/Jcrop.html and there is a weird problem it wont work while
I am using JCrop plugin to crop image, things are working good with following
I am trying to crop the image using JQuery Jcrop plugin with Java Stuff,
I am using Rails 3.0.7 and I am trying to follow this Railscast: http://railscasts.com/episodes/182-cropping-images
I am using the Jcrop plugin for jQuery for photo manipulation. I finally have
I am using the jQuery plugin Jcrop. I have an issue with one of
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button

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.