Announcement: V2 plans & fund raising
Please take a moment to read my plans for version 2 of the cropper and how you can support it.
Details
- 1.2.0
-
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
- 1.1.3
-
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
- 1.1.2
-
Fixed bugs with ratios when GCD is low (patch submitted by Andy Skelton)
- 1.1.1
-
Fixed bug with rendering issues fix in IE 5.5 Fixed bug with endCrop callback issues once cropper had been removed & reset in IE
- 1.1.0
-
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
- 1.0.0
-
Initial verison
About
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 script.aculo.us.
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 & script.aculo.us.
Features
![]()
Usage
Extract to a directory of your choosing e.g. 'scripts/cropper/' and include the script and the required Prototype & script.aculo.us scripts:
Options
- 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:
An example function which outputs the crop values to form fields:
Basic interface
This basic example will attach the cropper UI to the test image and return crop results to the provided callback function.
Minimum dimensions
You can apply minimum dimensions to a single axis or both, this example applies minimum dimensions to both axis.
Select area ratio
You can apply a ratio to the selection area, this example applies a 4:3 ratio to the select area.
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.
Known Issues
SEO Agency advanced JavaScript experience can enhance your site functionality. Adding the JavaScript Image Cropper is a good way to improve the user experience.
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.
Announcement: V2 plans & fund raising
Please take a moment to read my plans for version 2 of the cropper and how you can support it.

Comments
There have been 536 comments so far, join the discussion.
Pages: [27] 26 25 24 23 22 21 20 19 18 17 … 1 » Show All
536. Nitesh - 30th Oct 2008 - 12:25 pm
I have tried this control using Ajax ModalPopupExtender. The Crop Box is not getting displayed. Can any one please help me.
535. svempa - 15th Oct 2008 - 6:21 pm
cheers a million, just what I was trying to accomplish
534. Dave - 15th Oct 2008 - 5:14 pm
Svempa:
I’ve moved your question to the Google group, and have provided an example solution there also.
533. svempa - 15th Oct 2008 - 4:57 pm
Change ratio after cropper has been initiated.
This has been requested by a few people, but so far I have seen no working example. It was suggested that one take a look at the demo which has a CropImageManager class which allows the cropper to be removed and then reapplied using different settings. I have had a look at this demo, but I cannot make it work. I guess it should be easy, but my strongest skill is not js, so I’m not quite sure how to put together a function that could switch between different ratios. Would be great if someone could write a couple of lines of code to help me out…
Thanks in advance.
Otherwise a great looking tool.
[google does many good things, but their googlegroups is a pain in the butt. highly intrusive and takes some effort to join. googlegroups… no thanks]
532. TheIceman - 11th Oct 2008 - 9:37 pm
@ ingiltere ogrenci vizesi
1. we would rather the owner develop a new version of the script than worry about a bloody language problem on a website
2. cause the majority of people can speak english
3. cause the owner is not rich
4. cause it is not necessary
5. if it bothers you, volunteer to fix it.
531. ingiltere ogrenci vizesi - 11th Oct 2008 - 7:25 pm
Why this web site do not have other languages support?
530. peto - 8th Oct 2008 - 1:11 am
(I’m not posting this in Google Groups, because it wants me to join the group, which I’m not interested in. If you want people to post in a group, make it less restrictive…)
The examples load the cropper in onload. This causes visual glitches for me in FF3. When a default region is set, it takes a frame before it shows up, so the unfaded image flickers briefly. It also causes the preview to flicker briefly before overflow: hidden kicks in (this seems like an FF3 bug). I took the initialization out of onload and these go away.
I’d recommend documenting the auto-CSS-loading; better yet, remove it and include the CSS explicitly. It’s brittle; it took me a while to figure out why switching to cropper.uncompressed.js in the example broke everything (before I just renamed it and discarded the obfuscated one; I’ll let gzip handle compression). Most people that put CSS and JS files in different directories are also going to want to do it explicitly.
Unrelated patch:
Don’t intercept alt-left and alt-right; those are ubiquitous browser keys and it’s very disruptive to catch them. (I’m surprised FF3 even allows it.)
Add options.resizePreview (function). If set, this is called with the crop region size when the region changes to retrieve the desired preview image size. This allows previewing regions of varying aspect ratios, and fitting previews in a specified region.
This is backwards-compatible. If resizePreview is not set, minWidth and minHeight are used as before. If resizePreview is set, minWidth and minHeight are not used by the image preview.
This means that it’s possible to open a preview cropper with no default crop region; in this case, the preview won’t be displayed until the region is first set. To use resizePreview with a default region without using minWidth and minHeight, use options.onloadCoords instead.
(All changes are in the public domain.)
patch: http://pastebin.com/f9a0e690
example resizePreview: http://pastebin.com/f5a035683
529. Chris - 7th Oct 2008 - 6:04 pm
I just want to note that the DOCTYPE definition is CRUSIAL to this tool working properly in IE7. Tested under IE7, FF3, Opera 9 and Safari and so far, only IE7 malfunctions when it’s missing. Malfunctions range from blank divs (show as white, gray and black), to South (and sometimes North too) divs being black (no transparency). Took me a week to figure this out. Hope it can save people some time.
528. SleepingTroll - 27th Sep 2008 - 3:23 am
I have a problem with the cropper when I try to use the N & S handles for dragging, Rather than describe please visit site and try for yourself, the drag box jumps away from cursor.
527. Dave - 26th Sep 2008 - 10:14 pm
Rakesh:
Please ask this question on the Google group.
526. Rakesh - 26th Sep 2008 - 10:10 pm
Hi, I am Using this script of Image Croppper in my application. As per requriments when we click on Image then only crop selector display in an Image.. But my requirement is to Show Crop selector on Page Load with in Image. Top Left corner of Image(crop selector minimum width 75, height:75). Please Suggest me ..
525. Dave - 23rd Sep 2008 - 1:53 pm
Awnish:
Thanks for your comment, glad the cropper helps. Please see the FAQ’s for details on what to do to save images to your server.
524. Awnish - 23rd Sep 2008 - 1:49 pm
This is great script for image cropping tools. I have searched for many but this is the best. Just have few issues in saving the cropped image to the database and server, so can any one help me out there? How can i save the cropped images ?
523. Graham - 15th Sep 2008 - 9:56 pm
OK Never mind, it was to do with teh fact that the page IM using this on is in an iframe.
To get round this problem, I included the style sheet right there in the page instead of using the script to include it.
Sorry to a be nuesance
Graham
522. Dave - 15th Sep 2008 - 9:22 pm
Graham:
I have moved this question to the Google group.
521. Graham - 15th Sep 2008 - 9:09 pm
Dave, when I include the scripts on my own site they dont work, it only works when I link to yours….any idea why?
Leave a comment
No HTML please, only textile. For code please use [lang]...[/lang] tags (e.g. [html]...[/html] for HTML)