You are here

function _epsacrop_save_coords in EPSA Crop - Image Cropping 7.2

Same name and namespace in other branches
  1. 8.2 epsacrop.module \_epsacrop_save_coords()

Save the coordonates in the database.

@access private

Parameters

int $fid:

array $coords:

Return value

void

1 call to _epsacrop_save_coords()
epsacrop_ajax in ./epsacrop.module
epsacrop_ajax function.

File

./epsacrop.module, line 966
The main file of module

Code

function _epsacrop_save_coords($fid, $coords) {

  // Check fid is for a valid file.
  if ($file = file_load($fid)) {
    $info = image_get_info($file->uri);

    // Not an image.
    if (!$info) {
      return FALSE;
    }
    $coords_data = drupal_json_decode($coords);
    $field_coords = $coords_data[$fid];
    foreach ($field_coords as $field_coord) {

      // Check we have coordinates passed and that they are not larger
      // than the image.
      if (!empty($field_coord) && ($field_coord['x'] < 0 || $field_coord['y'] < 0 || $field_coord['x2'] > $info['width'] || $field_coord['y2'] > $info['height'])) {
        return FALSE;
      }
    }
    $affected = db_update('epsacrop_files')
      ->fields(array(
      'coords' => serialize($coords),
    ))
      ->condition('fid', $fid)
      ->execute();
    if ($affected == 0 && _epsacrop_fid_exists($fid) == 0) {
      _epsacrop_add_file($fid, $coords);
    }
    image_path_flush(_epsacrop_get_uri_from_fid($fid));
  }
}