/[drupal]/contributions/modules/imagefield/imagefield_file.inc
ViewVC logotype

Diff of /contributions/modules/imagefield/imagefield_file.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4, Wed Aug 27 14:53:56 2008 UTC revision 1.5, Sun Mar 1 04:28:54 2009 UTC
# Line 6  Line 6 
6   */   */
7    
8  /**  /**
9   * Implementation of hook_file().   * Implementation of hook_file_references().
10   */   */
11  function imagefield_file_references($file) {  function imagefield_file_references($file) {
12    $references = 0;    $references = 0;
# Line 19  function imagefield_file_references($fil Line 19  function imagefield_file_references($fil
19    return array('imagefield' => $references);    return array('imagefield' => $references);
20  }  }
21    
22    /**
23     * Implementation of hook_file_insert().
24     *
25     * Create an image thumbnail to be used as a preview when editing a node.
26     */
27  function imagefield_file_insert($file) {  function imagefield_file_insert($file) {
   // create and admin thumbnail.  
28    if (imagefield_file_is_image($file)) {    if (imagefield_file_is_image($file)) {
29      $info = image_get_info($file->filepath);      $info = image_get_info($file->filepath);
30      if($info['width'] < 100 || $info['height'] < 100) {      if($info['width'] < 100 || $info['height'] < 100) {
# Line 28  function imagefield_file_insert($file) { Line 32  function imagefield_file_insert($file) {
32        file_copy($newfile->filepath, imagefield_file_admin_thumb_path($newfile));        file_copy($newfile->filepath, imagefield_file_admin_thumb_path($newfile));
33      }      }
34      else {      else {
35        image_scale($file->filepath, imagefield_file_admin_thumb_path($file), 100, 100);        image_scale($file->filepath, imagefield_file_admin_thumb_path($file), 160, 160);
36      }      }
37    }    }
38  }  }
39    
40    /**
41     * Implementation of hook_file_delete().
42     *
43     * Delete the admin thumbnail when the original is deleted.
44     */
45  function imagefield_file_delete($file) {  function imagefield_file_delete($file) {
46    // delete admin thumbnail.    if (imagefield_file_is_image($file)) {
   if (imagefield_file_is_image($file))  
47      file_delete(imagefield_file_admin_thumb_path($file));      file_delete(imagefield_file_admin_thumb_path($file));
48      }
49  }  }
50    
51    /**
52  // test if a file is an image.   * Simple utility function to check if a file is an image.
53     */
54  function imagefield_file_is_image($file) {  function imagefield_file_is_image($file) {
55    $file = (object)$file;    $file = (object)$file;
   //dsm($file);  
56    return in_array($file->filemime, array('image/jpg', 'image/pjpeg', 'image/jpeg', 'image/png', 'image/gif'));    return in_array($file->filemime, array('image/jpg', 'image/pjpeg', 'image/jpeg', 'image/png', 'image/gif'));
57  }  }
58    
59  // create the path to and admin thumbnail.  /**
60     * Given a file, return the path the image thumbnail used while editing.
61     */
62  function imagefield_file_admin_thumb_path($file) {  function imagefield_file_admin_thumb_path($file) {
   //dsm($file);  
63    $file = (object)$file;    $file = (object)$file;
64    return $file->filepath .'.thumb.jpg';    return $file->filepath .'.thumb.jpg';
65  }  }
   
   

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.2