Index: /extensions/square_thumbnails/trunk/functions.inc.php
===================================================================
--- /extensions/square_thumbnails/trunk/functions.inc.php	(revision 9755)
+++ /extensions/square_thumbnails/trunk/functions.inc.php	(revision 9756)
@@ -154,13 +154,13 @@
   if (is_imagick())
   {
-    return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata);
-  }
-  else
-  {
-    return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality);
+    return upload_square_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata);
+  }
+  else
+  {
+    return upload_square_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality);
   }
 }
 
-function upload_square_resize_gd($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality)
+function upload_square_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality)
 {
   if (!function_exists('gd_info'))
@@ -175,9 +175,9 @@
   if (in_array($extension, array('jpg', 'jpeg')))
   {
-    $source_image = imagecreatefromjpeg($source_filepath);
+    $source_image = @imagecreatefromjpeg($source_filepath);
   }
   else if ($extension == 'png')
   {
-    $source_image = imagecreatefrompng($source_filepath);
+    $source_image = @imagecreatefrompng($source_filepath);
   }
   else
@@ -258,4 +258,72 @@
 }
 
+function upload_square_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false)
+{
+  // extension of the picture filename
+  $extension = strtolower(get_extension($source_filepath));
+  if (!in_array($extension, array('jpg', 'jpeg', 'png')))
+  {
+    die('[Imagick] unsupported file extension');
+  }
+
+  $image = new Imagick($source_filepath);
+
+  $rotation = get_rotation_angle($source_filepath);
+  
+  // width/height
+  $source_width  = $image->getImageWidth();
+  $source_height = $image->getImageHeight();
+
+  // Crop image -> square
+  $x = 0;
+  $y = 0;
+  if($source_width > $source_height)
+  {
+    $x = ceil(($source_width - $source_height) / 2 );
+    $source_width = $source_height;
+  }
+  elseif ($source_height > $source_width)
+  {
+    $y = ceil(($source_height - $source_width) / 2);
+    $source_height = $source_width;
+  }
+  $image->cropImage($source_width, $source_height, $x, $y);
+  
+  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
+
+  // testing on height is useless in theory: if width is unchanged, there
+  // should be no resize, because width/height ratio is not modified.
+  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height)
+  {
+    // the image doesn't need any resize! We just copy it to the destination
+    copy($source_filepath, $destination_filepath);
+    return true;
+  }
+
+  $image->setImageCompressionQuality($quality);
+  $image->setInterlaceScheme(Imagick::INTERLACE_LINE);
+  
+  if ($strip_metadata)
+  {
+    // we save a few kilobytes. For example a thumbnail with metadata
+    // weights 25KB, without metadata 7KB.
+    $image->stripImage();
+  }
+  
+  $image->resizeImage($resize_dimensions['width'], $resize_dimensions['height'], Imagick::FILTER_LANCZOS, 0.9);
+
+  if (isset($rotation))
+  {
+    $image->rotateImage(new ImagickPixel(), -$rotation);
+    $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
+  }
+
+  $image->writeImage($destination_filepath);
+  $image->destroy();
+
+  // everything should be OK if we are here!
+  return true;
+}
+
 add_event_handler('thumbnail_resize', 'thumbnail_square_resize', 40, 5);
 add_event_handler('upload_thumbnail_resize', 'upload_square_resize', 40, 6);
Index: /extensions/square_thumbnails/trunk/photo_add_settings.php
===================================================================
--- /extensions/square_thumbnails/trunk/photo_add_settings.php	(revision 9755)
+++ /extensions/square_thumbnails/trunk/photo_add_settings.php	(revision 9756)
@@ -43,5 +43,5 @@
 
 // Template init
-$template->assign('SQUARE', $conf['upload_form_thumb_square']);
+$template->assign('SQUARE', @$conf['upload_form_thumb_square']);
 
 // Add prefilter
