image_menu

7 image.module image_menu()
8 image.module image_menu()

Implements hook_menu().

File

modules/image/image.module, line 70
Exposes global functionality for creating image styles.

Code

function image_menu() {
  $items = array();

  // Generate image derivatives of publicly available files.
  // If clean URLs are disabled, image derivatives will always be served
  // through the menu system.
  // If clean URLs are enabled and the image derivative already exists,
  // PHP will be bypassed.
  $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
  $items[$directory_path . '/styles/%image_style'] = array(
    'title' => 'Generate image style', 
    'page callback' => 'image_style_deliver', 
    'page arguments' => array(count(explode('/', $directory_path)) + 1), 
    'access callback' => TRUE, 
    'type' => MENU_CALLBACK,
  );
  // Generate and deliver image derivatives of private files.
  // These image derivatives are always delivered through the menu system.
  $items['system/files/styles/%image_style'] = array(
    'title' => 'Generate image style', 
    'page callback' => 'image_style_deliver', 
    'page arguments' => array(3), 
    'access callback' => TRUE, 
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/media/image-styles'] = array(
    'title' => 'Image styles', 
    'description' => 'Configure styles that can be used for resizing or adjusting images on display.', 
    'page callback' => 'image_style_list', 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/list'] = array(
    'title' => 'List', 
    'description' => 'List the current image styles on the site.', 
    'page callback' => 'image_style_list', 
    'access arguments' => array('administer image styles'), 
    'type' => MENU_DEFAULT_LOCAL_TASK, 
    'weight' => 1, 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/add'] = array(
    'title' => 'Add style', 
    'description' => 'Add a new image style.', 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_style_add_form'), 
    'access arguments' => array('administer image styles'), 
    'type' => MENU_LOCAL_ACTION, 
    'weight' => 2, 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/edit/%image_style'] = array(
    'title' => 'Edit style', 
    'description' => 'Configure an image style.', 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_style_form', 5), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/delete/%image_style'] = array(
    'title' => 'Delete style', 
    'description' => 'Delete an image style.', 
    'load arguments' => array(NULL, (string) IMAGE_STORAGE_NORMAL), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_style_delete_form', 5), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/revert/%image_style'] = array(
    'title' => 'Revert style', 
    'description' => 'Revert an image style.', 
    'load arguments' => array(NULL, (string) IMAGE_STORAGE_OVERRIDE), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_style_revert_form', 5), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect'] = array(
    'title' => 'Edit image effect', 
    'description' => 'Edit an existing effect within a style.', 
    'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_effect_form', 5, 7), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect/delete'] = array(
    'title' => 'Delete image effect', 
    'description' => 'Delete an existing effect from a style.', 
    'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_effect_delete_form', 5, 7), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );
  $items['admin/config/media/image-styles/edit/%image_style/add/%image_effect_definition'] = array(
    'title' => 'Add image effect', 
    'description' => 'Add a new effect to a style.', 
    'load arguments' => array(5), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('image_effect_form', 5, 7), 
    'access arguments' => array('administer image styles'), 
    'file' => 'image.admin.inc',
  );

  return $items;
}

Comments

Is this magic?

Hi,

May anyone may explain me how this works?

  $items[$directory_path . '/styles/%image_style'] = array(
    'title' => 'Generate image style',
    'page callback' => 'image_style_deliver',
    'page arguments' => array(count(explode('/', $directory_path)) + 1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

In fact the first argument which image_style_deliver receives is an array but I am unable to see the magic making the string with the style-name "my_style_name" an array with the style definition (see below).

I am totally confused by this piece of code :-/

Array
(
    [effects] => Array
        (
            [0] => Array
                (
                    [label] => Scale
                    [help] => Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.
                    [effect callback] => image_scale_effect
                    [form callback] => image_scale_form
                    [summary theme] => image_scale_summary
                    [module] => image
                    [name] => image_scale
                    [data] => Array
                        (
                            [width] => 800
                            [height] => 800
                            [upscale] => 0
                        )

                    [weight] => 0
                )

            [1] =>
        )

    [name] => my_style_name
    [module] => some_module_name
    [storage] => 4
)

the answer would be ...

ok, I found it myself, should have better read the hook_menu documentation ;)

In fact '/styles/%image_style' calls the function image_style_load($presetname) ... which then would answer my question.

Login or register to post comments