image.install 3.24 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

/**
 * @file
 * Install, update and uninstall functions for the image module.
 */

/**
9
 * Implements hook_install().
10 11 12
 */
function image_install() {
  // Create the styles directory and ensure it's writable.
13 14
  $directory = file_default_scheme() . '://styles';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
15 16 17
}

/**
18
 * Implements hook_uninstall().
19 20 21
 */
function image_uninstall() {
  // Remove the styles directory and generated images.
22
  file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
23 24
}

25 26 27 28 29 30 31
/**
 * Implements hook_field_schema().
 */
function image_field_schema($field) {
  return array(
    'columns' => array(
      'fid' => array(
32
        'description' => 'The {file_managed}.fid being referenced in this field.',
33 34 35 36 37 38 39
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
      'alt' => array(
        'description' => "Alternative image text, for the image's 'alt' attribute.",
        'type' => 'varchar',
40
        'length' => 512,
41 42 43 44 45
        'not null' => FALSE,
      ),
      'title' => array(
        'description' => "Image title text, for the image's 'title' attribute.",
        'type' => 'varchar',
46
        'length' => 1024,
47 48
        'not null' => FALSE,
      ),
49 50 51 52 53 54 55 56 57 58
      'width' => array(
        'description' => 'The width of the image in pixels.',
        'type' => 'int',
        'unsigned' => TRUE,
      ),
      'height' => array(
        'description' => 'The height of the image in pixels.',
        'type' => 'int',
        'unsigned' => TRUE,
      ),
59 60 61 62
    ),
    'indexes' => array(
      'fid' => array('fid'),
    ),
63 64 65 66 67 68
    'foreign keys' => array(
      'fid' => array(
        'table' => 'file_managed',
        'columns' => array('fid' => 'fid'),
      ),
    ),
69 70 71
  );
}

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/**
 * Implements hook_requirements() to check the PHP GD Library.
 *
 * @param $phase
 */
function image_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    // Check for the PHP GD library.
    if (function_exists('imagegd2')) {
      $info = gd_info();
      $requirements['image_gd'] = array(
        'value' => $info['GD Version'],
      );

      // Check for filter and rotate support.
89
      if (!function_exists('imagefilter') || !function_exists('imagerotate')) {
90
        $requirements['image_gd']['severity'] = REQUIREMENT_WARNING;
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
        $requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="http://www.php.net/manual/book.image.php">the PHP manual</a>.');
      }
    }
    else {
      $requirements['image_gd'] = array(
        'value' => t('Not installed'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The GD library for PHP is missing or outdated. Check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/book.image.php')),
      );
    }
    $requirements['image_gd']['title'] = t('GD library rotate and desaturate effects');
  }

  return $requirements;
}