? Copy of audio.install
? Copy of audio_image.inc
? Copy of audio_images.install
? Copy of audio_images.module
? back.sql
? getid3
? test.patch
Index: audio_getid3.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio_getid3.module,v
retrieving revision 1.26
diff -u -r1.26 audio_getid3.module
--- audio_getid3.module	20 Jul 2007 14:44:50 -0000	1.26
+++ audio_getid3.module	20 Jul 2007 21:35:21 -0000
@@ -336,8 +336,7 @@
           if ($image_filepath = _audio_image_filename(basename($filepath), $image['mime'], $pictype, TRUE)) {
             // save it to the temp file
             if ($image_filepath = file_save_data($image['data'], $image_filepath, FILE_EXISTS_RENAME)) {
-              $image = _audio_image_get_info($image_filepath, $pictype);
-              $ret['images'][] = _audio_image_resize($image);
+              $ret['images'][] = audio_image_from_file($image_filepath, $pictype);
             }
           }
         }
Index: audio_image.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio_image.inc,v
retrieving revision 1.5
diff -u -r1.5 audio_image.inc
--- audio_image.inc	20 Feb 2007 19:25:21 -0000	1.5
+++ audio_image.inc	20 Jul 2007 21:35:51 -0000
@@ -66,26 +66,46 @@
 }
 
 /**
- * Build an audio image array from a filepath and pic type.
+ * Creates an audio image array from a filepath and pic type.
+ * 
+ * The image is cropped to a square and then resized to the image size setting.
+ * 
  * @param $filepath
- * @param $pictype one of the pictype indexes from
- *   audio_image_type_clean_array() or audio_image_type_dirty_array().
- * @returns an array with image info
+ *   Full path to the image file.
+ * @param $pictype
+ *   Integer pictype indexes from audio_image_type_clean_array() or 
+ *   audio_image_type_dirty_array().
+ * @return
+ *   An array with image info.
  */
-function _audio_image_get_info($filepath, $pictype) {
-  if ($info = getimagesize($filepath)) {
-    $extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
-    $extension = array_key_exists($info[2], $extensions) ? $extensions[$info[2]] : '';
-    $out = array(
+function audio_image_from_file($filepath, $pictype) {
+  if ($image = image_get_info($filepath)) {
+    // Crop to a square.
+    $size = min($image['width'], $image['height']);
+    if ($image['width'] != $image['height']) {
+      image_crop($filepath, $filepath, 0, 0, $size, $size);
+    }
+
+    // Resize to the maximum dimension.
+    $maxsize = variable_get('audio_image_size', 170);
+    if ($size > $maxsize) {
+      image_resize($filepath, $filepath, $maxsize, $maxsize);
+      $size = $maxsize;
+    }
+
+    // Changing the image dimensions will affect the file size. Clear out 
+    // PHP's cached value so we can find the new size.
+    clearstatcache();
+
+    return array(
       'pictype'   => $pictype,
       'filepath'  => $filepath,
-      'filemime'  => $info['mime'],
+      'filemime'  => $image['mime_type'],
       'filesize'  => filesize($filepath),
-      'extension' => $extension,
-      'width'     => $info[0],
-      'height'    => $info[1],
+      'extension' => $image['extension'],
+      'width'     => $size,
+      'height'    => $size,
     );
-    return $out;
   }
   return FALSE;
 }
@@ -125,37 +145,3 @@
   // combine the path and file extension from the mimetype
   return $directory .'/'. $prefix .'_'. $image_type . $ext;
 }
-
-/**
- * Crops (to square) and resizes to the image size setting. The image must have
- * already been saved to a file (who's path is stored in the path value).
- *
- * @param $audio_image array from _audio_image_get_info()
- * @return array with complete image info.
- */
-function _audio_image_resize($image) {
-  $width  = $image['width'];
-  $height = $image['height'];
-
-  // crop to a square
-  if ($width == $height) {
-    $size = $width;
-  }
-  else {
-    $size = min($width, $height);
-    image_crop($image['filepath'], $image['filepath'], 0, 0, $size, $size);
-  }
-
-  // resize down to the maximum dimention
-  $maxsize = variable_get('audio_image_size', 170);
-  if ($size > $maxsize) {
-    image_resize($image['filepath'], $image['filepath'], $maxsize, $maxsize);
-    $size = $maxsize;
-  }
-
-  // store the changes back in
-  $image['height'] = $image['width'] = $size;
-
-  return $image;
-}
-
Index: audio_images.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio_images.module,v
retrieving revision 1.17
diff -u -r1.17 audio_images.module
--- audio_images.module	20 Jul 2007 19:36:33 -0000	1.17
+++ audio_images.module	20 Jul 2007 21:35:06 -0000
@@ -116,8 +116,7 @@
         $pictype = (integer) $_POST['audio_images']['new']['pictype'];
         $imagepath = _audio_image_filename(basename($node->audio_file->filename), $upload->filemime, $pictype, TRUE);
         if ($file = file_save_upload($upload, $imagepath, FILE_EXISTS_REPLACE)) {
-          if ($image = _audio_image_get_info($file->filepath, $pictype)) {
-            $image = _audio_image_resize($image);
+          if ($image = audio_image_from_file($file->filepath, $pictype)) {
             $pid = 'new_'. count($_SESSION['audio_images']);
             $image['pid'] = $pid;
             $node->audio_images[$pid] = $image;
