Version 1.2.2
Last updated 4th July 2011
Demo View demo page
License BSD License
  • Support for latest versions of Prototype & (1.7.0 & 1.9.0 respectively)
  • Tested with & added support notice for IE9
  • Added support for latest versions of Prototype & ( & 1.8.2 respectively). Changes provided by Tom Hirashima.
  • No-longer package prototype & with the release
  • Changed tests to use google ajax libraries api to load prototype &
  • Added option to not auto include the cropper CSS file
  • #00008 - Fixed bug: Dynamic include of cropper CSS expected cropper.js and failed when using cropper.uncompressed.js
  • #00028 - Fixed bug: Doesn't work with latest - Fix by Tom Hirashima
  • #00030 - Fixed bug: Doesn't work in Firefox 3.5 (CSS include issue)
  • #00007 - Fixed bug: onEndCrop isn't called when moving with keys
  • #00011 - Fixed bug: The image that is to be cropped does not show in IE6.0 -- included CSS fix
  • Tidied up source code & fixed issues that jslint found so it will compress better
  • Added id to the preview image element using 'imgCrop_[originalImageID]'
  • #00001 - Fixed bug: Doesn't account for scroll offsets
  • #00009 - Fixed bug: Placing the cropper inside differently positioned elements causes incorrect co-ordinates and display
  • #00013 - Fixed bug: I-bar cursor appears on drag plane
  • #00014 - Fixed bug: If ID for image tag is not found in document script throws error
  • Fixed bug with drag start co-ordinates if wrapper element has moved in browser (e.g. dragged to a new position)
  • Fixed bug with drag start co-ordinates if image contained in a wrapper with scrolling - this may be buggy if image has other ancestors with scrolling applied (except the body)
  • #00015 - Fixed bug: When cropper removed and then reapplied onEndCrop callback gets called multiple times, solution suggestion from Bill Smith
  • Various speed increases & code cleanup which meant improved performance in Mac - which allowed removal of different overlay methods for IE and all other browsers, which led to a fix for:
  • #00010 - Fixed bug: Select area doesn't adhere to image size when image resized using img attributes
  • #00006 - Removed default behaviour of automatically setting a ratio when both min width & height passed, the ratioDimensions must be passed in
  • #00005 - Added ability to set maximum crop dimensions, if both min & max set as the same value then we'll get a fixed cropper size on the axes as appropriate and the resize handles will not be displayed as appropriate
  • Switched keydown for keypress for moving select area with cursor keys (makes for nicer action) - doesn't appear to work in Safari
  • Fixed wrong cursor on western handle in CSS
  • #00008 & #00003 - Added feature: Allow to set dimensions & position for cropper on load
  • #00002 - Fixed bug: Pressing 'remove cropper' twice removes image in IE
  • Fixed bugs with ratios when GCD is low (patch submitted by Andy Skelton)
  • Fixed bug with rendering issues fix in IE 5.5
  • Fixed bug with endCrop callback issues once cropper had been removed & reset in IE
  • Fixed bug with IE constantly trying to reload select area background image
  • Applied more robust fix to Safari & IE rendering issues
  • Added method to reset parameters - useful for when dynamically changing img the cropper is attached to
  • Added method to remove cropper from image
  • Initial verison


The JavaScript image cropper UI allows the user to crop an image using an interface with the same features and styling as found in commercial image editing software, and is is based on the Prototype JavaScript framework and

Initially I performed quite a lot of searching for some ready made solutions to meet my requirements, but found none that had the complete feature set that I required or any complete versions based on Prototype.

So after a week and a half of work, I present the JavaScript image cropper UI, built on Prototype &


Screen shot of cropper in action

  • Un-obtrusive
  • Based on Prototype and
  • Image editing package styling & functionality, the crop area functions and looks like those found in popular image editing software
  • Dynamic inclusion of required styles
  • Drag to draw areas
  • Shift drag to draw/resize areas as squares
  • Selection area can be moved
  • Selection area can be resized using resize handles
  • Allows dimension ratio limited crop areas
  • Allows minimum dimension crop areas
  • Allows maximum dimensions crop areas, if both min & max set as the same value then we'll get a fixed cropper size on the axes as appropriate and the resize handles will not be displayed as appropriate
  • Allows dynamic preview of resultant crop (if minimum width & height are provided), this is implemented as a subclass so can be removed if not required
  • Movement of selection area by arrow keys (shift + arrow key will move selection area by 10 pixels)
  • All operations stay within bounds of image
  • All functionality & display compatible with most popular browsers supported by Prototype, tested in:
    • PC: IE 6 & 5.5, Firefox 1.5, Opera 8.5 (see known issues) & 9.0b
    • MAC: Camino 1.0, Firefox 1.5, Safari 2.0


Extract to a directory of your choosing e.g. 'scripts/cropper/' and include the script and the required Prototype & scripts:

  1. <script type="text/javascript" src="scripts/cropper/lib/prototype.js" language="javascript"></script>
  2. <script type="text/javascript" src="scripts/cropper/lib/scriptaculous.js?load=effects,builder,dragdrop" language="javascript"></script>
  3. <script type="text/javascript" src="scripts/cropper/cropper.js" language="javascript"></script>


ratioDim obj
The pixel dimensions to apply as a restrictive ratio, with properties x & y.
minWidth int
The minimum width for the select area in pixels.
minHeight int
The mimimum height for the select area in pixels.
maxWidth int
The maximum width for the select areas in pixels (if both minWidth & maxWidth set to same the width of the cropper will be fixed)
maxHeight int
The maximum height for the select areas in pixels (if both minHeight & maxHeight set to same the height of the cropper will be fixed)
displayOnInit int
Whether to display the select area on initialisation, only used when providing minimum width & height or ratio.
onEndCrop func
The callback function to provide the crop details to on end of a crop.
captureKeys boolean
Whether to capture the keys for moving the select area, as these can cause some problems at the moment.
onloadCoords obj
A coordinates object with properties x1, y1, x2 & y2; for the coordinates of the select area to display onload

The callback function

The callback function is a function that allows you to capture the crop co-ordinates when the user finished a crop movement, it is passed two arguments:

  • coords, obj, coordinates object with properties x1, y1, x2 & y2; for the coordinates of the select area.
  • dimensions, obj, dimensions object with properities width & height; for the dimensions of the select area.

An example function which outputs the crop values to form fields:

  1. function onEndCrop( coords, dimensions ) {
  2.     $( 'x1' ).value = coords.x1;
  3.     $( 'y1' ).value = coords.y1;
  4.     $( 'x2' ).value = coords.x2;
  5.     $( 'y2' ).value = coords.y2;
  6.     $( 'width' ).value = dimensions.width;
  7.     $( 'height' ).value = dimensions.height;
  8. }

Basic interface

This basic example will attach the cropper UI to the test image and return crop results to the provided callback function.

  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  3.     <script type="text/javascript" language="javascript">
  4.     Event.observe( window, 'load', function() {
  5.         new Cropper.Img(
  6.             'testImage',
  7.             { onEndCrop: onEndCrop }
  8.         );
  9.     } );
  10. </script>

Minimum dimensions

You can apply minimum dimensions to a single axis or both, this example applies minimum dimensions to both axis.

  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  3. <script type="text/javascript" language="javascript">
  4.     Event.observe( window, 'load', function() {
  5.         new Cropper.Img(
  6.             'testImage',
  7.             {
  8.                 minWidth: 220,
  9.                 minHeight: 120,
  10.                 onEndCrop: onEndCrop
  11.             }
  12.         );
  13.     } );
  14. </script>

Select area ratio

You can apply a ratio to the selection area, this example applies a 4:3 ratio to the select area.

  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  3. <script type="text/javascript" language="javascript">
  4.     Event.observe( window, 'load', function() {
  5.         new Cropper.Img(
  6.             'testImage',
  7.             {
  8.                 ratioDim: {
  9.                     x: 220,
  10.                     y: 165
  11.                 },
  12.                 displayOnInit: true,
  13.                 onEndCrop: onEndCrop
  14.             }
  15.         );
  16.     } );
  17. </script>

With crop preview

You can display a dynamically produced preview of the resulting crop by using the ImgWithPreview subclass, a preview can only be displayed when we have a fixed size (set via minWidth & minHeight options). Note that the displayOnInit option is not required as this is the default behaviour when displaying a crop preview.

  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  2. <div id="previewWrap"></div>
  4. <script type="text/javascript" language="javascript">
  5.     Event.observe( window, 'load', function() {
  6.         new Cropper.ImgWithPreview(
  7.             'testImage',
  8.             {
  9.                 previewWrap: 'previewWrap',
  10.                 minWidth: 120,
  11.                 minHeight: 120,
  12.                 ratioDim: { x: 200, y: 120 },
  13.                 onEndCrop: onEndCrop
  14.             }
  15.         );
  16.     } );
  17. </script>

Known Issues

  • Safari animated gifs, only one of each will animate, this seems to be a known Safari issue.
  • After drawing an area and then clicking to start a new drag in IE 5.5 the rendered height appears as the last height until the user drags, this appears to be the related to another IE error (which has been fixed) where IE does not always redraw the select area properly.
  • Lack of CSS opacity support in Opera before version 9 mean we disable those style rules, if Opera 8 support is important you & you want the overlay to work then you can use the Opera rules in the CSS to apply a black PNG with 50% alpha transparency to replicate the effect.
  • Styling & borders on image, any CSS styling applied directly to the image itself (floats, borders, padding, margin, etc.) will cause problems with the cropper. The use of a wrapper element to apply these styles to is recommended.
  • overflow: auto or overflow: scroll on parent will cause cropper to burst out of parent in IE and Opera when applied (maybe Mac browsers too) I'm not sure why yet.

Next Steps

Feature Requests & Bug Reports

Please check the existing list of feature requests & bugs and the discussion list before posting requests or reporting bugs.

Leave a Tip

If you find this code useful you can leave a donation towards the continued development & support.


Note: Please only use the comments for general comments and the discussion list to discuss this code project (e.g. implementation queries, change suggestions etc.).


There have been 786 comments so far, join the discussion.

Pages: « 1108 109 110 111 112 113 114 115 116 117 [118] Show All

5851. WilliamDes - 15th Jan 2017 - 10:35 pm

cm4653 rr1077 [URL=]canadian pharmacy[/url] op8965 sh3507 sq573 [URL=]uk generic cialis tadalafil[/url] yo4979 rt3759 is5927 [URL=]cialis generic reviews[/url] jc1756

5852. Licktain73r - 15th Jan 2017 - 10:35 pm

Hey !! My name is BULAH WONG. I am staying at Truro [URL=].[/url] I am turning 22. I want to study at The Clean Military School in Santa Barbara . I am working as Pedologist. My hobby is Crystals and Rocks. My father name is Nevin and he is a Librettist. My mother is a Dramatist.

5853. BryanKen - 15th Jan 2017 - 10:41 pm

hd2837 kt1945 [URL=]cheap levitra[/url] yq3507 iw7419 ku8978 [URL=]cialis[/url] vw1416 wp8462 cf3325 [URL=]cheap viagra[/url] xt5059

5854. sildenafil - 15th Jan 2017 - 11:26 pm sildenafil,

5855. learn more - 16th Jan 2017 - 12:45 am Seroquel,

5856. potenshöjande medel - 16th Jan 2017 - 1:11 am levitra,

5857. buy abilify online - 16th Jan 2017 - 1:38 am generic for abilify,

5858. doxycycline - 16th Jan 2017 - 2:05 am buy doxycycline without prescription uk,

5859. propranolol generic - 16th Jan 2017 - 2:15 am propranolol,

5860. prozac - 16th Jan 2017 - 2:23 am prozac online,

5861. buy valtrex online without a prescription - 16th Jan 2017 - 3:00 am valtrex discount,

5862. zovirax online - 16th Jan 2017 - 3:18 am acyclovir prices,

5863. buy retin-a online - 16th Jan 2017 - 4:20 am retin a pill,

5864. glucophage xr - 16th Jan 2017 - 4:56 am glucophage xr 500mg,

5865. Donaldjoulk - 16th Jan 2017 - 5:02 am

[URL=]personlig trening bali[/url]
[URL=]treningsfrue boller[/url]
[URL=]treningsprogram forsvaret PDF[/url]
[URL=]personlig trening utdanning bergen[/url]
[URL=]treningsprogram maraton 12 uker[/url]

A personal trainer is an distinct certified to maintain a varying scale of knowledge of catholic healthiness enmeshed with in harry prescription and instruction. They tempt clients by environment goals and providing feedback and responsibility to clients. Trainers also measure their patient’s strengths and weaknesses with competence assessments.

[URL=]personlig trener bali[/url]
[URL=]personlig trener utdanning los angeles[/url]

These wholesomeness assessments may also be performed beforehand and after an apply program to measure their patron’s improvements in true fitness. They may also indoctrinate their clients in diverse other aspects of wellness in addition to workout, including non-exclusive condition and nutrition guidelines.

5866. angelanw11 - 16th Jan 2017 - 5:26 am

Hi new work

milson twins porn 3g free mobile porn hwere cani get free psp porn POP art porn jenny mccarthy saturday night live porn

5867. buy elimite - 16th Jan 2017 - 5:32 am buy elimite,

5868. DavidEntiz - 16th Jan 2017 - 5:37 am

??????? ??????? ???? [URL=]??????? ??????? ????...[/url]

5869. buy clindamycin - 16th Jan 2017 - 6:34 am clindamycin,

5870. AlegorSit - 16th Jan 2017 - 6:36 am

Loan tukwila wa amc theatres

If you suspect abuse, overlook or financial exploitation, or perhaps if you are concerned about the quality of care a person is receiving in a extensive care facility that is certified by the state, contact the state of hawaii Department of Social and also Health Services Complaint Res Unit by calling on 1-800-562-6078 or 1-866-ENDHARM (363-4276). Long-term care facilites include adult family homes, made it easier for living facilities, nursing homes, residential habilitation centers and reinforced living programs.

Suspected mistreatment or neglect of an elderly person living in their own residence or somewhere other than a new residential care facility should be reported to the Adult Protecting Services (APS) office with your county. A list of APS offices can be found on DSHS’ web page at:

[URL=]payday loan werribee open[/url]
[URL=]aeon personal loan 2016[/url]
[URL=]federal stafford loan disbursement[/url]
[URL=] payday loans[/url]
[URL=]small cash loans no credit checks[/url]

5871. advair - 16th Jan 2017 - 6:43 am buy advair,

5872. rolex day date acier faux - 16th Jan 2017 - 7:08 am

cartierbraceletlove Don’t forget, Philly will be ahead of the curve. All the violence and misery, but 5-10 years earlier!

rolex day date acier faux

5873. AltonWrams - 16th Jan 2017 - 7:16 am

Guaranteed Overnight Delivery USA Viagra Samples from Pfizer
Overnight delivery usa
viagra overnight shipping usa

5874. cialis - 16th Jan 2017 - 7:36 am cialis – 20 mg,

5876. nolvadex pct buy - 16th Jan 2017 - 8:01 am pct nolvadex,

5877. hauntthehouse3 - 16th Jan 2017 - 8:04 am

Usually I do not read post on blogs, but I would like to say that this write-up very pressured me to try and do it! Your writing style has been amazed me. Thanks, quite nice article.

5878. visit the website - 16th Jan 2017 - 8:54 am

I’m extremely impressed with your writing skills as well as with the layout
on your weblog. Is this a paid theme or did you modify it yourself?
Anyway keep up the excellent quality writing, it is rare to see
a nice blog like this one these days.

5879. Annasmir - 16th Jan 2017 - 9:07 am

?????? ???????? ????? ? ?????? ???????????? ???????????:
????????????? ?? ??????????? ????? ????? ? ????? ?? 900 000 ?????? ?? ????? ????,
?????? ????????? ????? ?? 800 ???????????? ? ????? ?? ????? ?? ?????? ? ??? ?? ???.
??????? ????? ????? ?????????? ????????????? ?????, ??????? ????????
??????? + ????? ? ?????????? ?? 30% ?? ????????? ? ?? ???????? ?? ???????????.
?????????????, ??????? ????????? ??????????, ?? ???????? ????? ???????????? ?????? ????.

5880. amoxicillin - 16th Jan 2017 - 10:01 am amoxicillin,

5881. augmentin 875 - 16th Jan 2017 - 10:10 am augmentin 875,

5882. dustinfs4 - 16th Jan 2017 - 10:28 am

My revitalized page

erotic expeirences erotic letters nudes erotic chat bot erotid PDF

5883. tetracycline orders without a prescription - 16th Jan 2017 - 10:37 am tetracycline online,

Pages:« 1108 109 110 111 112 113 114 115 116 117 [118] Show All

Leave a comment

No HTML please, only textile. For code please use [lang]...[/lang] tags (e.g. [html]...[/html] for HTML)