Index: imagecrop.js
===================================================================
--- imagecrop.js	(revision 378)
+++ imagecrop.js	(working copy)
@@ -15,7 +15,7 @@
 		handles: 'all',
 		knobHandles: true,
 		//transparent: true,
-		aspectRatio: false,
+		aspectRatio: Drupal.settings.aspect,
 		autohide: true,
 
 		resize: function(e, ui) {
@@ -40,7 +40,7 @@
 		  $("#edit-image-crop-y").val(ui.position.top);
 		}
 	});
-	
+
 	$('#image-crop-container').css({ opacity: 0.5 });
     var leftpos = $('#edit-image-crop-x').val();
     var toppos = $('#edit-image-crop-y').val();
Index: imagecrop.module
===================================================================
--- imagecrop.module	(revision 378)
+++ imagecrop.module	(working copy)
@@ -230,7 +230,7 @@
         while ($form[$formfield[$i]][$a]['#default_value']['fid']) {
           //drupal_set_message('moeahahah');
           if (!empty($form[$formfield[$i]][$a]['#default_value']['fid'])) {
-            $descr = $form[$formfield[$i]][$a]['#default_value']['description']['#value'] .'<br />'. 
+            $descr = $form[$formfield[$i]][$a]['#default_value']['description']['#value'] .'<br />'.
               imagecrop_linkitem($form[$formfield[$i]][$a]['#default_value']['fid']);
             $form[$formfield[$i]][$a]['#description'] = imagecrop_linkitem($form[$formfield[$i]][$a]['#default_value']['fid']);
           }
@@ -333,21 +333,31 @@
       $width = $size[0];
       $height = $size[1];
       // return warning message if crop toolbox is too big and not resizable.
-      if (($width < $file->crop_width || $height < $file->crop_height) && $file->resizable == 0) {
+      if (($width < $file->crop_width || $height < $file->crop_height) && $file->data['resizable'] == 0) {
         $size_warning = FALSE;
       }
 
       // add jquery ui
-      if ($file->resizable)
-      jquery_ui_add(array('ui.resizable', 'ui.draggable', 'effects.scale'));
-      else
-      jquery_ui_add(array('ui.draggable'));
+      if ($file->data['resizable']) {
+        jquery_ui_add(array('ui.resizable', 'ui.draggable', 'effects.scale'));
 
+        // set aspect ration if needed
+        if ($file->data['aspect']) {
+          drupal_add_js(array('aspect' => $file->data['width'] / $file->data['height']), 'setting');
+
+          // just in case, set the initial aspect ratio of the crop region
+          $file->crop_width = round(($file->data['width'] * $file->crop_height) / $file->data['height']);
+        }
+      }
+      else {
+        jquery_ui_add(array('ui.draggable'));
+      }
+
       // output
       if ($size_warning == FALSE) {
         $url = file_create_url($file->dst) .'?time='. time();
         $output .= '<div id="imagecrop_info"  class="imagecrop_warning">'. t('Even if you think this crop is ok, press the submit button!') .'</div>';
-        $output .= theme('imagecrop', $url, $width, $height, $file->resizable);
+        $output .= theme('imagecrop', $url, $width, $height, $file->data['resizable']);
         $output .= drupal_get_form('imageoffsets', $file->xoffset, $file->yoffset, $file->crop_width, $file->crop_height, $presetid, $fid, $module, $file->orig_width, $file->scale);
       }
       else {
@@ -377,16 +387,56 @@
  * @return array $form
  */
 function imageoffsets(&$form_state, $xoffset, $yoffset, $crop_width, $crop_height, $presetid, $fid, $module, $width, $scale) {
-  $form['buttons']['submit'] = array('#prefix' => '<table style="width: 400px; margin: 0;" id="imagecrop_table_actions"><tr><td>', '#suffix' => '</td>', '#type' => 'submit', '#value' => t('Create crop'));
-  $form['buttons']['scaling'] = array('#prefix' => '<td>', '#suffix' => '</td>', '#type' => 'select', '#default_value' => $scale, '#options' => imagecrop_scale_options($width, $crop_width));
-  $form['button']['scaledown'] = array('#prefix' => '<td>', '#suffix' => '</td></tr></table>', '#type' => 'submit', '#value' => t('Scale image'));
-  $form['image-crop-x'] = array('#type' => 'hidden', '#default_value' => $xoffset, '#attributes' => array('class' => 'edit-image-crop-x'));
-  $form['image-crop-y'] = array('#type' => 'hidden', '#default_value' => $yoffset, '#attributes' => array('class' => 'edit-image-crop-y'));
-  $form['image-crop-width'] = array('#type' => 'hidden', '#default_value' => $crop_width, '#attributes' => array('class' => 'edit-image-crop-width'));
-  $form['image-crop-height'] = array('#type' => 'hidden', '#default_value' => $crop_height, '#attributes' => array('class' => 'edit-image-crop-height'));
-  $form['fid'] = array('#type' => 'hidden', '#value' => $fid);
-  $form['module'] = array('#type' => 'hidden', '#value' => $module);
-  $form['presetid'] = array('#type' => 'hidden', '#value' => $presetid);
+  $form['buttons']['submit'] = array(
+    '#prefix' => '<table style="width: 400px; margin: 0;" id="imagecrop_table_actions"><tr><td>',
+    '#suffix' => '</td>',
+    '#type' => 'submit',
+    '#value' => t('Create crop')
+  );
+  $form['buttons']['scaling'] = array(
+    '#prefix' => '<td>',
+    '#suffix' => '</td>',
+    '#type' => 'select',
+    '#default_value' => $scale,
+    '#options' => imagecrop_scale_options($width, $crop_width)
+  );
+  $form['button']['scaledown'] = array(
+    '#prefix' => '<td>',
+    '#suffix' => '</td></tr></table>',
+    '#type' => 'submit',
+    '#value' => t('Scale image')
+  );
+  $form['image-crop-x'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $xoffset,
+   '#attributes' => array('class' => 'edit-image-crop-x')
+  );
+  $form['image-crop-y'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $yoffset,
+    '#attributes' => array('class' => 'edit-image-crop-y')
+  );
+  $form['image-crop-width'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $crop_width,
+    '#attributes' => array('class' => 'edit-image-crop-width')
+  );
+  $form['image-crop-height'] = array('#type' => 'hidden',
+    '#default_value' => $crop_height,
+    '#attributes' => array('class' => 'edit-image-crop-height')
+  );
+  $form['fid'] = array(
+    '#type' => 'hidden',
+    '#value' => $fid
+  );
+  $form['module'] = array(
+    '#type' => 'hidden',
+    '#value' => $module
+  );
+  $form['presetid'] = array(
+    '#type' => 'hidden',
+    '#value' => $presetid
+  );
   return $form;
 }
 
@@ -398,7 +448,8 @@
  * @return possible width options
  */
 function imagecrop_scale_options($width, $cropboxwidth) {
-  $options['original'] = 'Original ('. $width .'px)';
+  $options['original'] = t('Original (!sizepx)', array('!size' => $width));
+
   // experimental, we give the width always a bit more
   $cropboxwidth += 60;
   while ($width > $cropboxwidth) {
@@ -421,12 +472,16 @@
   }
   $module = (!empty($form_state['values']['module'])) ? '/'. $form_state['values']['module'] : '';
   $reference = (!empty($form_state['values']['module'])) ? $form_state['values']['module'] : 'files';
+
   db_query("DELETE FROM {imagecrop} WHERE fid=%d AND presetid=%d AND reference = '%s'", $form_state['values']['fid'], $form_state['values']['presetid'], $reference);
   db_query("INSERT INTO {imagecrop} VALUES (%d,%d,'%s',%d,%d,%d,%d,'%s')", $form_state['values']['fid'], $form_state['values']['presetid'], $reference, $form_state['values']['image-crop-x'], $form_state['values']['image-crop-y'], $form_state['values']['image-crop-width'], $form_state['values']['image-crop-height'], $form_state['values']['scaling']);
-  if ($form_state['values']['op'] == t('Scale image'))
+
+  if ($form_state['values']['op'] == t('Scale image')) {
     drupal_goto('imagecrop/docrop/'. $form_state['values']['fid'] .'/'. $form_state['values']['presetid'] . $module);
-  else
+  }
+  else {
     drupal_goto('imagecrop/showcrop/'. $form_state['values']['fid'] .'/'. $form_state['values']['presetid'] . $module);
+  }
 }
 
 
@@ -470,8 +525,14 @@
   while ($row = db_fetch_object($result)) {
     $presets['tabs'][] = array('id' => $row->presetid, 'name' => $row->presetname);
   }
-  if (!empty($presetid)) $presets['presetid'] = $presetid;
-  else $presets['presetid'] = $presets['tabs'][0]['id'];
+
+  if (!empty($presetid)) {
+    $presets['presetid'] = $presetid;
+  }
+  else {
+    $presets['presetid'] = $presets['tabs'][0]['id'];
+  }
+
   return $presets;
 }
 
@@ -491,36 +552,33 @@
     if ($cutoff == FALSE) {
       // get the actions from the preset and and throw out the javascript_crop action
       // and every other action which comes after it.
-      $break = FALSE;
       while (list($key, $val) = each($preset['actions'])) {
         if ($val['action'] == 'imagecrop_javascript') {
-          $crop_width = $preset['actions'][$key]['data']['width'];
-          $crop_height = $preset['actions'][$key]['data']['height'];
-          $resizable = $preset['actions'][$key]['data']['resizable'];
+          $file->data = $preset['actions'][$key]['data'];
           $break = TRUE;
         }
         if ($break == TRUE) {
           unset($preset['actions'][$key]);
         }
       }
+
       // see if we have stored values allready for this file
-      $file->xoffset = 0;
-      $file->yoffset = 0;
-      $file->crop_width = $crop_width;
-      $file->crop_height = $crop_height;
+
       $reference = (!empty($module)) ? $module : 'files';
-      $row = db_fetch_object(db_query("SELECT xoffset,yoffset,width,height,scale FROM {imagecrop} ic where ic.fid = %d AND ic.presetid = %d AND ic.reference = '%s'", $fid, $presetid, $reference));
-      $firstscale = FALSE;
+      $row = db_fetch_object(db_query("SELECT xoffset, yoffset, width, height, scale FROM {imagecrop} ic where ic.fid = %d AND ic.presetid = %d AND ic.reference = '%s'", $fid, $presetid, $reference));
+
       if (!empty($row)) {
         $file->xoffset = $row->xoffset;
         $file->yoffset = $row->yoffset;
         $file->crop_width = $row->width;
         $file->crop_height = $row->height;
         $file->scale = $row->scale;
+
         $firstscale = TRUE;
+      } else {
+        $file->crop_width = $file->data['width'];
+        $file->crop_height = $file->data['height'];
       }
-      // resizable or not
-      $file->resizable = $resizable;
 
       // add scale action if necessary
       if ($row->scale != 'original' && $firstscale == TRUE) {
@@ -563,18 +621,24 @@
   else if ($module == 'node_images') {
     $result = db_query('SELECT * FROM {node_images} WHERE id = %d', $fid);
   }
+
   $file = db_fetch_object($result);
+
   if ($file) {
     // make sure it's an image. Any other mime extensions possible?
     // return false if it's not the right mime type
     $filemime = array('image/jpeg', 'image/gif', 'image/png', 'image/pjpeg');
-    if (!in_array($file->filemime, $filemime)) return FALSE;
+    if (!in_array($file->filemime, $filemime)) {
+      return FALSE;
+    }
+
     // access denied if current user hasn't enough permissions
     $node = node_load($file->nid);
     if (!user_access('administer nodes') && !user_access('edit '. $node->type .' content') && !user_access('edit own '. $node->type .' content')) {
       drupal_access_denied();
       exit();
     }
+
     // all seems ok, return file
     return $file;
   }
@@ -640,6 +704,11 @@
  */
 function imagecrop_markup($js, $css) {
   $path = drupal_get_path('module', 'imagecrop');
-  if ($js == TRUE) drupal_add_js($path .'/imagecrop.js');
-  if ($css == TRUE) drupal_add_css($path .'/imagecrop.css');
+  if ($js == TRUE) {
+    drupal_add_js($path .'/imagecrop.js');
+  }
+
+  if ($css == TRUE) {
+    drupal_add_css($path .'/imagecrop.css');
+  }
 }
Index: imagecrop_actions.inc
===================================================================
--- imagecrop_actions.inc	(revision 383)
+++ imagecrop_actions.inc	(working copy)
@@ -40,6 +40,11 @@
     '#title' => t('Is the toolbox resizable or not?'),
     '#default_value' => $data['resizable'],
   );
+  $form['aspect'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Lock aspect ratio?'),
+    '#default_value' => $data['aspect'],
+  );
   $form['disable_if_no_data'] = array(
     '#type' => 'checkbox',
     '#title' => t('Don\'t crop if cropping region wasn\'t set'),
