You are here

function media_watermark_install in Media watermark 7

Implements hook_install().

File

./media_watermark.install, line 70
Media watermark module install file.

Code

function media_watermark_install() {
  $style = image_style_save(array(
    'name' => 'media_watermark',
  ));
  $effect = array(
    'name' => 'image_scale',
    'data' => array(
      'width' => 200,
      'height' => NULL,
      'upscale' => FALSE,
    ),
    'isid' => $style['isid'],
  );
  image_effect_save($effect);

  // Need to prepare default watermarks.
  $data = array(
    'linux' => array(
      'file' => 'linux.png',
      'name' => 'png watermark',
    ),
    'drupal' => array(
      'file' => 'drupal-watermark.gif',
      'name' => 'gif watermark',
    ),
  );
  foreach ($data as $value) {
    $path = drupal_get_path('module', 'media_watermark') . '/includes/img/' . $value['file'];
    $file_temp = file_get_contents($path);
    $file_temp = file_save_data($file_temp, 'public://watermark' . $value['file'], FILE_EXISTS_RENAME);
    global $user;
    file_usage_add($file_temp, 'media_watermark', 'image', $user->uid);
    db_insert('media_watermark')
      ->fields(array(
      'fid' => $file_temp->fid,
      'name' => $value['name'],
      'hor_position' => 'left',
      'ver_position' => 'bottom',
      'hor_margin' => '0',
      'ver_margin' => '0',
    ))
      ->execute();
  }
}