X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fcommands%2Fcore%2Fimage.drush.inc;fp=vendor%2Fdrush%2Fdrush%2Fcommands%2Fcore%2Fimage.drush.inc;h=e4bb4f9916b20b34a6dbd1d3a010a898f6bc8833;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drush/drush/commands/core/image.drush.inc b/vendor/drush/drush/commands/core/image.drush.inc new file mode 100644 index 000000000..e4bb4f991 --- /dev/null +++ b/vendor/drush/drush/commands/core/image.drush.inc @@ -0,0 +1,130 @@ + 'Flush all derived images for a given style.', + 'core' => array('7+'), + 'arguments' => array( + 'style' => 'An image style machine name. If not provided, user may choose from a list of names.', + ), + 'options' => array( + 'all' => 'Flush all derived images', + ), + 'examples' => array( + 'drush image-flush' => 'Pick an image style and then delete its images.', + 'drush image-flush thumbnail' => 'Delete all thumbnail images.', + 'drush image-flush --all' => 'Flush all derived images. They will be regenerated on the fly.', + ), + 'aliases' => array('if'), + ); + $items['image-derive'] = array( + 'description' => 'Create an image derivative.', + 'core' => array('7+'), + 'drupal dependencies' => array('image'), + 'arguments' => array( + 'style' => 'An image style machine name.', + 'source' => 'Path to a source image. Optionally prepend stream wrapper scheme.', + ), + 'required arguments' => TRUE, + 'options' => array(), + 'examples' => array( + 'drush image-derive thumbnail themes/bartik/logo.png' => 'Save thumbnail sized derivative of logo image.', + ), + 'aliases' => array('id'), + ); + return $items; +} + +/** + * Implements hook_drush_help_alter(). + */ +function image_drush_help_alter(&$command) { + // Drupal 8+ customizations. + if ($command['command'] == 'image-derive' && drush_drupal_major_version() >= 8) { + unset($command['examples']); + $command['examples']['drush image-derive thumbnail core/themes/bartik/logo.png'] = 'Save thumbnail sized derivative of logo image.'; + } +} + +/** + * Command argument complete callback. + * + * @return + * Array of available configuration files for editing. + */ +function image_image_flush_complete() { + drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL); + drush_include_engine('drupal', 'image'); + return array('values' => array_keys(drush_image_styles())); +} + +function drush_image_flush_pre_validate($style_name = NULL) { + drush_include_engine('drupal', 'image'); + if (!empty($style_name) && !$style = drush_image_style_load($style_name)) { + return drush_set_error(dt('Image style !style not recognized.', array('!style' => $style_name))); + } +} + +function drush_image_flush($style_name = NULL) { + drush_include_engine('drupal', 'image'); + if (drush_get_option('all')) { + $style_name = 'all'; + } + + if (empty($style_name)) { + $styles = array_keys(drush_image_styles()); + $choices = array_combine($styles, $styles); + $choices = array_merge(array('all' => 'all'), $choices); + $style_name = drush_choice($choices, dt("Choose a style to flush.")); + if ($style_name === FALSE) { + return drush_user_abort(); + } + } + + if ($style_name == 'all') { + foreach (drush_image_styles() as $style_name => $style) { + drush_image_flush_single($style_name); + } + drush_log(dt('All image styles flushed'), LogLevel::SUCCESS); + } + else { + drush_image_flush_single($style_name); + } +} + +function drush_image_derive_validate($style_name, $source) { + drush_include_engine('drupal', 'image'); + if (!$style = drush_image_style_load($style_name)) { + return drush_set_error(dt('Image style !style not recognized.', array('!style' => $style_name))); + } + + if (!file_exists($source)) { + return drush_set_error(dt('Source file not found - !file.', array('!file' => $source))); + } +} + +/* + * Command callback. Create an image derivative. + * + * @param string $style_name + * The name of an image style. + * + * @param string $source + * The path to a source image, relative to Drupal root. + */ +function drush_image_derive($style_name, $source) { + drush_include_engine('drupal', 'image'); + return _drush_image_derive($style_name, $source); +}