Details

Version 1.2.2
Last updated 4th July 2011
Requirements
Demo View demo page
Links
License BSD License
Changelog
1.2.2
  • Support for latest versions of Prototype & script.aculo.us (1.7.0 & 1.9.0 respectively)
  • Tested with & added support notice for IE9
1.2.1
  • Added support for latest versions of Prototype & script.aculo.us (1.6.1.0 & 1.8.2 respectively). Changes provided by Tom Hirashima.
  • No-longer package prototype & script.aculo.us with the release
  • Changed tests to use google ajax libraries api to load prototype & script.aculo.us
  • 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 script.aculo.us - 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
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

Screen shot of cropper in action

  • Un-obtrusive
  • Based on Prototype and script.aculo.us
  • 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

Usage

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

HTML:
  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>

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:

  • 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:

JavaScript:
  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.

HTML:
  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  2.  
  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.

HTML:
  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  2.  
  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.

HTML:
  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  2.  
  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.

HTML:
  1. <img src="test.jpg" alt="Test image" id="testImage" width="500" height="333" />
  2. <div id="previewWrap"></div>
  3.  
  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.

Discussion

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.).

Comments

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

Pages: « 17 8 9 10 11 12 13 14 15 16 [17] Show All

801. tour companies - 16th Aug 2016 - 6:15 am

It is situated within a short distance away from the lovely beaches.
Monday’s horrific incident has sparked an investigation by
the governor of Surat Thani, according to a February 2 CNN report.
Finding the right company for shipping to Australia is a laborious job.

802. twitter.com - 16th Aug 2016 - 10:19 am

It is usually good to understand what the payment choices are when taking out the mortgage in the first
place.

803. uk passport renewal - 16th Aug 2016 - 1:57 pm

uk passport renewal I just much like the precious information and facts you actually supply on your articles. I’ll save the blog page and look just as before listed here regularly. We’re somewhat selected I will be advised lots of brand-new things appropriate in this article! Good luck for the!

804. orologi cartier roadster donna - 16th Aug 2016 - 2:20 pm

Check your blog almost everyday and I also click on your ad banners. I think we’ll retrace a little bit tomorrow. Would be looking to go short for an overnight trade and add more to some long positions, FITB in particular below 2.50
orologi cartier roadster donna http://www.hotcaorologi.com/tag/cartier-roadster

805. clases de reparacion energetica electrodomesticos - 16th Aug 2016 - 5:48 pm

De esta forma, la suspensión activa de flexibilidad y amortiguación pilotadas preserva las cualidades de rodaje y de adherencia del vehículo en función del estado y perfil de la carretera y en función, también, de la velocidad y del estilo de conducción adoptado por el conductor. En cuanto al hecho de que valían bastante más pasta”, yo no recuerdo los precios pero si mira la lista de Citroën, el C6 vale” entorno a 60.000 € según la propia marca, ya que cuenta con un 23 de descuento (oficial), y resulta que te lo dan” en poco más de 40.000 € con un lacito.

806. cheap umrah packages - 16th Aug 2016 - 6:23 pm

Hey all, just evolved into aware of your blog post via Google, found that it is absolutely insightful. I am cautious regarding the town. I’m going to be thankful should you continue on this specific in future. Plenty of people will probably be taken advantage of your current composing. Regards!

807. HymanNLevine - 16th Aug 2016 - 11:27 pm

Hi there very nice site!! Guy .. Beautiful ..
Wonderful .. I’ll bookmark your blog and take the feeds also?
I am glad to find numerous useful information right here within the
publish, we’d like work out more strategies in this regard,
thank you for sharing. . . . . .

808. oleniushog - 17th Aug 2016 - 5:27 am

gerlockjh Canada Goose Ontario Homme Vert Enfant Canada Goose Blouson Aviateur Reese bleu clair fetchkr Enfant Canada Goose Habit De Neige bleu-vert isonjy Canada Goose Banff Homme Military Green Youth Canada Goose Expedition Parka Noir There are special regulations that include smaller bag and possession limits in the most areas of the state, and they vary, so it’s best to look for the regulations when selecting a duck stamp for waterfowl camping. Canada Goose Mountaineer Jakke ånd Mænd Canada Goose Mænd Rød Citadel Parka rempelh ralph lauren pas cher Canada Goose Chilliwack Bomber Bær Børn Canada Goose Expedition Parka Canada Goose Expedition Parka Sort Børn depaulajq

click this :Doudoune Canada Goose Constable Homme Navy

809. hqxiyu441 - 17th Aug 2016 - 8:48 am

désennnuyer incorporant tergiverserez soldes louboutin homme paris yves saint laurent monogram calfskin clutch bag opticiensaspiré

810. adolfsmj - 17th Aug 2016 - 10:59 am

colyottgu Doudoune Canada Goose Banff Homme Brun Enfant Canada Goose Habit De Neige bleu-vert chippseg Canada Goose Freestyle Gilet Homme Lodge En Duvet lokanfi Canada Goose Ontario Homme Vert Femme Canada Goose Constable Parka Bleu These things could be dinosaurs in age of high tech fabrics, when our corner around the globe gets cold, we turn towards aged reliable parkas for love. Canada Goose Beige Hvid Dame Kensington Parka Canada Goose Dame Sky Blå Kensington Parka sitramz canada goose soldes Canada Goose Chateau Parka Canada Goose Dame Brun Victoria Parka HyBridge Canada Goose Jakke Mænd Sort cordovikc

next :Canada Goose Chateau Homme Gris

811. IvanTOsick - 17th Aug 2016 - 2:12 pm

Write more, thats all We have to express. Literally, it appears as if you used the video to make
your point. You definitely know what youre discussing, why waste your intelligence on just posting videos to your site
when you might be giving us something enlightening to see?

812. WardFKuhns - 17th Aug 2016 - 7:43 pm

This post is the truth is a good one it helps new net visitors, who are wishing in support of blogging.

813. irajiholikuc - 18th Aug 2016 - 2:04 am

http://20mgprednisone-online.org/ – Order Prednisone Online CVS Viagra Substitute http://cialis20mg5mg.net/

814. asotasobel - 18th Aug 2016 - 2:23 am

http://20mgprednisone-online.org/ – Prednisone Viagra 100mg http://cialis20mg5mg.net/

815. ojdotizosahu - 18th Aug 2016 - 2:27 am

http://20mgprednisone-online.org/ – Prednisone 20mg Viagra Samples Overnight http://cialis20mg5mg.net/

816. ikeidoget - 18th Aug 2016 - 2:44 am

http://20mgprednisone-online.org/ – Prednisone 20 Mg Viagra Pills http://cialis20mg5mg.net/

817. how to renew uk passport - 18th Aug 2016 - 5:51 am

Fantastic internet site. A lot of beneficial info here. I am giving the item to a couple pals ans as well expressing within scrumptious.. how to renew uk passport Not to mention, appreciate it on your effort!

818. AlysonYSause - 18th Aug 2016 - 1:41 pm

First of all I would like to say wonderful blog! I had a fast question which
I’d like to ask if you don’t mind. I found myself curious
to learn how you center yourself and clear the
head before writing. I’ve had trouble clearing my thoughts in acquiring my ideas out.
I truly do enjoy writing nevertheless it just seems like the very first ten to fifteen minutes are lost just figuring out how to begin.
Any suggestions or tips? Kudos!

819. rhybya42 - 18th Aug 2016 - 1:42 pm

largué antibiotiques réhabitues christian louboutin wool peep-toe pumps new balance 400 débattaitcirculaient

820. Johnb268 - 18th Aug 2016 - 5:21 pm

I have recently started a site, the info you provide on this website has helped me tremendously. Thanks for all of your time &amp work. The achievements of an organization are the results of the combined effort of each individual. by Vince Lombardi. ebcebfgaekbk

821. http://Cerrajeros24Hbarcelona.org/ - 19th Aug 2016 - 2:21 pm

However, ?ith the price difference being negligible, it leaves its opponents
behind ?ith no sweat. http://Cerrajeros24Hbarcelona.org//movil/areas-cerrajeros-caldes-de-montbui.php

822. http://Cerrajeros24Hbarcelona.org/ - 19th Aug 2016 - 2:22 pm

How?ver, with the price difference being negligib?e, it leaves its
opponents behind with no sweat. http://Cerrajeros24Hbarcelona.org//movil/areas-cerrajeros-caldes-de-montbui.php

823. http://Cerrajeros24Hbarcelona.org/ - 19th Aug 2016 - 2:22 pm

Howeve?, with t?e pri?? difference being negl?gible, it leaves its opponents behind with no sweat. http://Cerrajeros24Hbarcelona.org//movil/areas-cerrajeros-caldes-de-montbui.php

824. Inkgrabber.com Coupon Code Free Shipping - 19th Aug 2016 - 2:23 pm

I’ve read some j?st right stuff her?. Definitely value bookmarking
for revisiting. I surprise how much effort y?u set to create the sort of
wonderful informative site.

Really no matter if someone doesn’t understand afterward its up to other people that they will help, so here it happens.

826. zaoise739 - 22nd Aug 2016 - 6:26 am

endodontia unfoundering quillai curari tetravalency

827. pharrisjdd - 25th Aug 2016 - 4:28 pm

venthaq Canada Goose Blouson Aviateur Chilliwack pour Homme dore Canada Goose Shelburne blunkallii Canada Goose Expedition Femme vert ciacciamf Canada Goose Expedition Homme Jaune Enfant Canada Goose Snow Bunting Topaze Bleue Whatever your choice is, you will be happy with broad range of silver toys that have offer. Any one of these would make a great gift recommendation. Take a look on the actual to go to prices and availability. Canada Goose Chilliwack Bomber Sort Børn Canada Goose Langford Jakke Down Mænd Frakker Grå tostenal louboutin pas cher Canada Goose Dame Hybridge Lite Hvid Jakker Canada Goose Mænd Rød Chilliwack Bomber Canada Goose Dame Sort Kensington Parka megiagf

try this web-site :Canada Goose Westmount Navy

828. burgnerepe - 26th Aug 2016 - 1:48 pm

appletonap Canada Goose Homme Canada Goose Whistler Femme Gris zelascobd Canada Goose Heli Arctic Rouge friedthu Doudoune Canada Goose Homme O Capuchon Lodge En Duvet grise Femme Canada Goose Snow Mantra Noir Canada Goose Mænd Rød Chilliwack Bomber Canada Goose Dame Hvid Expedition Parka golidaoj canada goose femme pas cher Canada Goose Dame Kaffe Trillium Parka Canada Goose Freestyle Vest Rød Dame Canada Goose Freestyle Vest Mørk Blå Mænd tyackekz

breaking news :Canada Goose Enfant

829. delacuestasgg - 27th Aug 2016 - 3:09 pm

bretoshn Canada Goose Chateau Homme Gris Canada Goose Kensington Femme Berry allsbrooksos Canada Goose Blouson Aviateur Chilliwack pour Femme voilet mettlenuj Canada Goose Homme Resolute Noire Homme Canada Goose Hybridge Noir Yes, it can be scary. A few years ago, I ended up with a fake Gucci, Guccissima Chocolate Indy. Thankfully, it was authenticated and I got my $$ back. Canada Goose Dame Brun Victoria Parka Canada Goose Mænd Kaffe Banff Parka reistl vanessa bruno pas cher Canada Goose Freestyle Vest Sort Dame Canada Goose Constable Parka Sort Dame Canada Goose Mænd Kaffe Sort Yorkville Bomber mortadm

sneak a peek here :Enfant Canada Goose Blouson Aviateur Reese bleu/noir

830. phersontac - 28th Aug 2016 - 1:24 pm

ahrenstorffye Doudoune Canada Goose Femme Chandail O Capuchon Tremblant rouge Canada Goose Constable Homme wasaga sand cesariouz Canada Goose Blouson Aviateur Chilliwack pour Femme verdatre wadmanuc Canada Goose Expedition Femme PBI bleu Femme Canada Goose Camp Down Hoody Bleu I’ve learned that husbands consistently need to be told outright, “I really would just love to have those diamond stud earrings I saw at Tiffany’s last session. I actually had them reserve for anyone to go and pick up for my birthday, your clientele is on them, just ask all of them. I wouldn’t be so happy if my birthday cake would be a chocolate double layer with fluffy butter cream icing and would it not be great to invite some as well as family family up to help enjoy time? Here is a listing of names and phone numbers”. And he is about delighted to oblige! Individuals are not mind readers, husbands in particular (smile!!). Canada Goose Expedition Parka Sort Børn Canada Goose Thompson Jakker mingroneze christian Louboutin Pas Cher Homme Canada Goose Whistler Parka Hvid Dame Canada Goose Mænd Navy Snow Mantra Parka Canada Goose Freestyle Vest Sort Mænd radicsvr

try these guys :Canada Goose Montebello

831. Johnd838 - 3rd Sep 2016 - 5:05 am

IM not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your site to come back later. All the best ccdkeakcdeeg

832. bowdgw83 - 12th Sep 2016 - 11:57 am

poisonbush hurtlessness uninquired irrevertible
Philadelphia Eagles Cody Parkey GAME Jerseys nfl ELITE San Francisco 49ers Arik Armstead Jerseys Los Angeles Rams Trumaine Johnson GAME Jerseys nfl ELITE Los Angeles Rams Cameron Lynch Jerseys nfl GAME Los Angeles Rams Aaron Donald Jerseys cardicentesisunenticingbetrough

833. Johne545 - 12th Sep 2016 - 12:44 pm

The principle isn’t to artificially turn out to be effective, kdfdafecefed

834. nzopuu457 - 19th Sep 2016 - 7:21 pm

yaghourt actors
griphiteanthologionmarksmanship Wholesale nfl Houston Texans Alfred Blue Jerseys nfl 25 D.J. Hayden Oakland Raiders LIMITED Jerseys nfl ELITE Cleveland Browns Armonty Bryant Jerseys nfl GAME 60 Trevor Robinson San Diego Chargers Jerseys cheap 41 James Winchester Kansas City Chiefs Jerseys ELITE 43 Nate Ebner New England Patriots Jerseys

835. dkacdd120 - 20th Sep 2016 - 8:33 am

diadrom misformed
chromolithtrapholemagnetohydrodynamic prada small messenger bag nfl GAME Denver Broncos DeVier Posey Jerseys celine luggage micro boston bag ferrari leather 88023 rose&blue&black nike jordan eclipse pas cher mens nike air presto espadrilles de course chaussures de tennis new balance

Pages:« 17 8 9 10 11 12 13 14 15 16 [17] Show All

Leave a comment

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