7

I want to start JCrop selection in the center of the picture. Is there a way to do it?

Is there a option or something? It's not specified in the manual.

Do we have to calculate it manually?

3
  • No -__- Of course I tries many things. Can you help or not? Nothing in the manual. Please, be polite.
    – Thermech
    Dec 3, 2012 at 19:58
  • @Thermech what everyone wants to say (I assume) is that you should give enough evidence in your question which helps the community believe that you have put some efforts in solving the problem. Give examples of what you have tried and what didn't work out etc. I am somehow unable to find the question on meta which talked about asking the right way.
    – TJ-
    Dec 3, 2012 at 20:08
  • Thanks TJ, it's more clear when said like that ;)
    – Thermech
    Dec 3, 2012 at 20:14

1 Answer 1

17

In case you are not able to figure out how to set the selection in the centre :

Check the setting options http://deepliquid.com/content/Jcrop_Manual.html#Setting_Options

Something like this (taken from the API ref) :

<script language="Javascript">

    jQuery(function($) {
        $('#target').Jcrop({
            onSelect:    showCoords,
            bgColor:     'black',
            bgOpacity:   .4,
            setSelect:   [ x, y, x1, y1 ],
            aspectRatio: 16 / 9
        });
    });

</script>

If w is the width and h is the height of the desired selection and W is the width of the image, H is the height of the image, the coordinates will be

x = W/2 - w/2
y = H/2 - h/2
x1 = x + w
y1 = y + h

(I hope my math is right :)

2
  • Thanks, great code! I'll share my full code to help someone needs: var w = 189; var h = 250.5; var W = canvasOriginal.width; var H = canvasOriginal.height; var x = W / 2 - w / 2; var y = H / 2 - h / 2; var x1 = x + w; var y1 = y + h; $('#canvas').Jcrop({ onSelect: App.saveImageCrop, setSelect:[ x, y, x1, y1 ], }); May 4, 2017 at 16:16
  • fing love you man, probably saved me over 8 hours...
    – Seabizkit
    Oct 24, 2020 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.