Index: chessboard_render.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chessboard/chessboard_render.php,v
retrieving revision 1.16.2.11
diff -u -p -r1.16.2.11 chessboard_render.php
--- chessboard_render.php	30 Nov 2010 21:12:24 -0000	1.16.2.11
+++ chessboard_render.php	14 Dec 2010 11:21:54 -0000
@@ -111,22 +111,82 @@ function template_preprocess_chessboard(
 
   if (!isset($variables['element']['#image_directory_path'])) {
     $variables['element']['#image_directory_path'] = drupal_get_path('module', 'chessboard') . '/default';
-    $getsize = TRUE;
-  }
-  else {
-    $getsize_test_path = chessboard_piece_filename('-', 0, $variables['element']['#image_directory_path'] . '/');
-    $getsize = is_file($getsize_test_path) && (list($width, $height) = @getimagesize($getsize_test_path));
   }
   $image_directory_path = $variables['element']['#image_directory_path'];
   if (!isset($tables_xhtml[$image_directory_path])) {
+    $groups = array('square', 'border-h', 'border-v', 'border-c');
+    $test_paths = array(
+      'square' => chessboard_piece_filename('-', 0, $image_directory_path . '/'),
+      'border-h' => chessboard_border_filename('T', $image_directory_path . '/'),
+      'border-v' => chessboard_border_filename('R', $image_directory_path . '/'),
+      'border-c' => chessboard_border_filename('TR', $image_directory_path . '/'),
+    );
+    $class_attributes = array(
+      'square' => array(
+        'class' => 'chessboard-square',
+      ),
+      'border-h' => array(
+        'class' => 'chessboard-border-h',
+      ),
+      'border-v' => array(
+        'class' => 'chessboard-border-v',
+      ),
+      'border-c' => array(
+        'class' => 'chessboard-border-c',
+      ),
+    );
+    $default_image_directory_path = drupal_get_path('module', 'chessboard') . '/default';
+    if ($image_directory_path === $default_image_directory_path) {
+      $size_attributes = array(
+        'square' => array(
+          'width' => 40,
+          'height' => 40,
+        ),
+        'border-h' => array(
+          'width' => 40,
+          'height' => 4,
+        ),
+        'border-v' => array(
+          'width' => 4,
+          'height' => 40,
+        ),
+        'border-c' => array(
+          'width' => 4,
+          'height' => 4,
+        ),
+      );
+    }
+    foreach ($test_paths as $group => $test_path) {
+      if (!isset($size_attributes[$group]) && is_file($test_path) && (list($width, $height) = @getimagesize($test_path))) {
+        // The order matters;
+        $size_attributes[$group] = array(
+          'width' => $width,
+          'height' => $height,
+        );
+      }
+    }
+    
+    $group_attributes = array();
+    foreach ($groups as $group) {
+      if (!isset($size_attributes[$group])) {
+        $size_attributes[$group] = array();
+      }
+      if (!isset($class_attributes[$group])) {
+        $class_attributes[$group] = array();
+      }
+
+      // The order matters.
+      $group_attributes[$group] = $size_attributes[$group] + $class_attributes[$group];
+    }
+
     // Construct the translation table
 
     // Empty and marked squares
     $table_xhtml = array(
-      '-0' => theme('image', chessboard_piece_filename('-', 0, $image_directory_path . '/'), '-', NULL, array('class' => 'chessboard-square'), $getsize),
-      '-1' => theme('image', chessboard_piece_filename('-', 1, $image_directory_path . '/'), '-', NULL, array('class' => 'chessboard-square'), $getsize),
-      'x0' => theme('image', chessboard_piece_filename('x', 0, $image_directory_path . '/'), 'x', NULL, array('class' => 'chessboard-square'), $getsize),
-      'x1' => theme('image', chessboard_piece_filename('x', 1, $image_directory_path . '/'), 'x', NULL, array('class' => 'chessboard-square'), $getsize),
+      '-0' => strtr(theme('image', chessboard_piece_filename('-', 0, $image_directory_path . '/'), '-', NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+      '-1' => strtr(theme('image', chessboard_piece_filename('-', 1, $image_directory_path . '/'), '-', NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+      'x0' => strtr(theme('image', chessboard_piece_filename('x', 0, $image_directory_path . '/'), 'x', NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+      'x1' => strtr(theme('image', chessboard_piece_filename('x', 1, $image_directory_path . '/'), 'x', NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
     );
 
     // Pieces
@@ -134,23 +194,23 @@ function template_preprocess_chessboard(
     for ($i=0; $i<6; $i++) {
       $piece = $pieces[$i];
       $table_xhtml += array(
-        strtoupper($piece) . '0' => theme('image', chessboard_piece_filename(strtoupper($piece), 0, $image_directory_path . '/'), strtoupper($piece), NULL, array('class' => 'chessboard-square'), $getsize),
-        strtoupper($piece) . '1' => theme('image', chessboard_piece_filename(strtoupper($piece), 1, $image_directory_path . '/'), strtoupper($piece), NULL, array('class' => 'chessboard-square'), $getsize),
-        $piece . '0' => theme('image', chessboard_piece_filename($piece, 0, $image_directory_path . '/'), $piece, NULL, array('class' => 'chessboard-square'), $getsize),
-        $piece . '1' => theme('image', chessboard_piece_filename($piece, 1, $image_directory_path . '/'), $piece, NULL, array('class' => 'chessboard-square'), $getsize),
+        strtoupper($piece) . '0' => strtr(theme('image', chessboard_piece_filename(strtoupper($piece), 0, $image_directory_path . '/'), strtoupper($piece), NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+        strtoupper($piece) . '1' => strtr(theme('image', chessboard_piece_filename(strtoupper($piece), 1, $image_directory_path . '/'), strtoupper($piece), NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+        $piece . '0' => strtr(theme('image', chessboard_piece_filename($piece, 0, $image_directory_path . '/'), $piece, NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
+        $piece . '1' => strtr(theme('image', chessboard_piece_filename($piece, 1, $image_directory_path . '/'), $piece, NULL, $group_attributes['square'], FALSE), array('"  ' => '" ')),
       );
     }
 
     // Borders
     $table_xhtml += array(
-      'T' => theme('image', chessboard_border_filename('T', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-h'), $getsize),
-      'B' => theme('image', chessboard_border_filename('B', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-h'), $getsize),
-      'L' => theme('image', chessboard_border_filename('L', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-v'), $getsize),
-      'R' => theme('image', chessboard_border_filename('R', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-v'), $getsize),
-      'TL' => theme('image', chessboard_border_filename('TL', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-c'), $getsize),
-      'TR' => theme('image', chessboard_border_filename('TR', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-c'), $getsize),
-      'BL' => theme('image', chessboard_border_filename('BL', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-c'), $getsize),
-      'BR' => theme('image', chessboard_border_filename('BR', $image_directory_path . '/'), '', NULL, array('class' => 'chessboard-border-c'), $getsize),
+      'T' => strtr(theme('image', chessboard_border_filename('T', $image_directory_path . '/'), '', NULL, $group_attributes['border-h'], FALSE), array('"  ' => '" ')),
+      'B' => strtr(theme('image', chessboard_border_filename('B', $image_directory_path . '/'), '', NULL, $group_attributes['border-h'], FALSE), array('"  ' => '" ')),
+      'L' => strtr(theme('image', chessboard_border_filename('L', $image_directory_path . '/'), '', NULL, $group_attributes['border-v'], FALSE), array('"  ' => '" ')),
+      'R' => strtr(theme('image', chessboard_border_filename('R', $image_directory_path . '/'), '', NULL, $group_attributes['border-v'], FALSE), array('"  ' => '" ')),
+      'TL' => strtr(theme('image', chessboard_border_filename('TL', $image_directory_path . '/'), '', NULL, $group_attributes['border-c'], FALSE), array('"  ' => '" ')),
+      'TR' => strtr(theme('image', chessboard_border_filename('TR', $image_directory_path . '/'), '', NULL, $group_attributes['border-c'], FALSE), array('"  ' => '" ')),
+      'BL' => strtr(theme('image', chessboard_border_filename('BL', $image_directory_path . '/'), '', NULL, $group_attributes['border-c'], FALSE), array('"  ' => '" ')),
+      'BR' => strtr(theme('image', chessboard_border_filename('BR', $image_directory_path . '/'), '', NULL, $group_attributes['border-c'], FALSE), array('"  ' => '" ')),
     );
     $tables_xhtml[$image_directory_path] = $table_xhtml;
   }
