You are here

function manualcrop_load_crop_selection in Manual Crop 7

Gets the crop area for an image.

Parameters

$file: Path to an image file.

$style_name: Image style machine name, leave empty for all styles.

Return value

When $style_name is set, a single crop selection will be returned. Otherwise the result is an array of crop selection objects keyed by style name. Each object contains following items:

  • "style_name": The machine name of the image style this cropping area applies on.
  • "x": An integer representing the top left corner's x-position in pixels.
  • "y": An integer representing the top left corner's y-position in pixels.
  • "width": An integer representing the width in pixels.
  • "height": An integer representing the height in pixels.
6 calls to manualcrop_load_crop_selection()
manualcrop_croptool_process in ./manualcrop.helpers.inc
Add a croptool to the form element. This extends the FAPI widget or simply adds a new form item to enable cropping in a regular form.
manualcrop_crop_and_scale_effect in ./manualcrop.module
Image effect callback; Crop and scale an image resource.
manualcrop_crop_effect in ./manualcrop.module
Image effect callback; Crop an image resource.
manualcrop_file_presave in ./manualcrop.module
Implements hook_file_presave().
_manualcrop_add_cache_control in ./manualcrop.helpers.inc
Adds a cache control parameter to the image URI so the image will be reloaded if the crop selection was changed since it was last feched by the browser.

... See full list

File

./manualcrop.helpers.inc, line 638
Helper functions for the Manual Crop module.

Code

function manualcrop_load_crop_selection($file, $style_name = NULL) {
  $query = db_select('manualcrop', 'mc');
  $use_revisions = module_exists('file_entity_revisions');
  if ($use_revisions) {
    $query
      ->join('file_managed_revisions', 'r', 'mc.vid = r.vid AND r.uri = :uri', array(
      ':uri' => $file,
    ));
  }
  else {
    $query
      ->join('file_managed', 'f', 'mc.fid = f.fid');
    $query
      ->condition('f.uri', $file);
  }
  $query
    ->fields('mc', array(
    'x',
    'y',
    'width',
    'height',
    'style_name',
  ));
  if (isset($style_name)) {
    $query
      ->condition('mc.style_name', $style_name);
    if ($use_revisions) {

      // Order by file revision ID descending to use the most recent Manual
      // Crop settings associated with the provided file URI.
      $query
        ->orderBy('r.vid', 'DESC');
      $query
        ->range(0, 1);
    }
    return $query
      ->execute()
      ->fetchObject();
  }
  else {
    if ($use_revisions) {

      // The fetchAllAssoc() call below will use the last result found by this
      // query for each style name, so order it by file revision ID ascending
      // to use the most recent Manual Crop settings associated with the
      // provided file URL for each style.
      $query
        ->orderBy('r.vid', 'ASC');
    }
    return $query
      ->execute()
      ->fetchAllAssoc('style_name');
  }
}