You are here

function tinypng_load_library in TinyPNG 7

Load TinyPNG library.

1 call to tinypng_load_library()
image_tinypng_save in ./tinypng.module
GD helper to write an image resource to a destination file.

File

./tinypng.module, line 42
Provides TinyPNG integration.

Code

function tinypng_load_library() {
  $dir = libraries_get_path(TINIFY_PHP_DIRNAME);
  if (!$dir) {
    drupal_set_message(t('You have to download Tinify PHP library from !link', array(
      '!link' => l('https://github.com/tinify/tinify-php/', 'https://github.com/tinify/tinify-php/'),
    )));
  }
  $api_key = variable_get('tinypng_api_key');
  if (!$dir || !$api_key) {
    return FALSE;
  }
  $files = array(
    'lib/Tinify.php',
    'lib/Tinify/Client.php',
    'lib/Tinify/Exception.php',
    'lib/Tinify/ResultMeta.php',
    'lib/Tinify/Result.php',
    'lib/Tinify/Source.php',
  );
  foreach ($files as $file) {
    $path = $dir . '/' . $file;
    if (is_readable($path)) {
      require_once $path;
    }
  }
  Tinify\setKey($api_key);
  Tinify\setAppIdentifier('Drupal/' . VERSION);
  return TRUE;
}