$info['GD Version'],
);
// Check for filter and rotate support.
if (!function_exists('imagefilter') || !function_exists('imagerotate')) {
$requirements['image_gd']['severity'] = REQUIREMENT_WARNING;
$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 the PHP manual.', array('@url' => 'http://www.php.net/manual/book.image.php'));
}
}
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 PHP image documentation 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;
}
/**
* Loads all effects for an image style from backend.
*
* @param array $style
* The image style (array) to retrieve effects for.
*
* @return array
* An array of effects keyed by UUIDs.
*
* @see image_update_8000()
*/
function _image_update_get_backend_effects(array $style) {
$result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC))
->fields('image_effects')
->condition('isid', $style['isid'])
->execute();
$effects = array();
foreach ($result as $effect) {
$effect['data'] = unserialize($effect['data']);
$effects[] = $effect;
}
return _image_update_convert_effects($effects);
}
/**
* Retuns the default image styles shipped with Drupal 7.
*
* @return array
* An associative array keyed by style id, having the style and associated
* effects as values. The array values are defined to be usable in
* image_update_8000().
*
* @see image_update_8000()
* @see https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_image_default_styles/7
*/
function _image_update_get_default_styles() {
// Clone from Drupal 7 image_image_default_styles().
$styles = array(
'thumbnail' => array(
'label' => 'Thumbnail (100x100)',
'effects' => array(
array(
'name' => 'image_scale',
'data' => array(
'width' => '100',
'height' => '100',
'upscale' => '1',
),
'weight' => '0',
),
),
),
'medium' => array(
'label' => 'Medium (220x220)',
'effects' => array(
array(
'name' => 'image_scale',
'data' => array(
'width' => '220',
'height' => '220',
'upscale' => '1',
),
'weight' => '0',
),
),
),
'large' => array(
'label' => 'Large (480x480)',
'effects' => array(
array(
'name' => 'image_scale',
'data' => array(
'width' => '480',
'height' => '480',
'upscale' => '0',
),
'weight' => '0',
),
),
),
);
// Add uuid, status, langcode and convert effects.
$langcode = language_default()->id;
$uuid = \Drupal::service('uuid');
foreach ($styles as $id => $style) {
$styles[$id]['name'] = $id;
$styles[$id]['uuid'] = $uuid->generate();
$styles[$id]['status'] = 1;
$styles[$id]['langcode'] = $langcode;
$styles[$id]['effects'] = _image_update_convert_effects($style['effects']);
}
return $styles;
}
/**
* Normalizes effects from Drupal 7 to Drupal 8 format.
*
* @param array $legacy_effects
* An array containing a list of effects obtained from database or from code.
*
* @return array
* A list of effects keyed by effect uuid and having the effect definition in
* a Drupal 8 configuration format.
*/
function _image_update_convert_effects(array $legacy_effects) {
$uuid = \Drupal::service('uuid');
$effects = array();
foreach ($legacy_effects as $effect) {
$effect['uuid'] = $uuid->generate();
// Use 'id' instead of 'name'.
$effect['id'] = $effect['name'];
// Clear out legacy keys, if case.
unset($effect['isid'], $effect['ieid'], $effect['name']);
$effects[$effect['uuid']] = $effect;
}
return $effects;
}
/**
* Convert existing image styles to the new config system.
*/
function image_update_8000() {
$langcode = language_default()->id;
$uuid = \Drupal::service('uuid');
$result = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC))
->fields('image_styles')
->execute();
// Prepare image styles from backend.
$styles = array();
foreach ($result as $style) {
$styles[$style['name']] = array(
'name' => $style['name'],
'label' => $style['label'],
'uuid' => $uuid->generate(),
'status' => 1,
'langcode' => $langcode,
'effects' => _image_update_get_backend_effects($style),
);
}
// Append Drupal 7 default image styles from code. Note that some of them may
// be overwritten in the backend. Using this array operator assures that we
// are migrating the overwritten version of the image style.
$styles += _image_update_get_default_styles();
// Save as Drupal 8 configuration.
foreach ($styles as $id => $style) {
\Drupal::config('image.style.' . $id)
->setData($style)
->save();
}
}
/**
* Empty update. See http://drupal.org/node/1980058.
*/
function image_update_8001() {
}
/**
* Moves image module settings from variable to config.
*
* @ingroup config_upgrade
*/
function image_update_8002() {
update_variables_to_config('image.settings', array(
'image_style_preview_image' => 'preview_image',
));
}