コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function transformDimensions(array &$dimensions, $uri)
 {
     $entity_manager = \Drupal::entityManager();
     $files = $entity_manager->getStorage('file')->loadByProperties(array('uri' => $uri));
     $file = NULL;
     if (count($files)) {
         $file = reset($files);
         $info = imagefield_crop_get_file_info($file->id());
         if ($info) {
             // The new image will have the exact dimensions defined for the effect.
             $dimensions['width'] = $info['width'];
             $dimensions['height'] = $info['height'];
         }
     }
 }
コード例 #2
0
 public static function addCropInfoFields($fid = NULL)
 {
     $element = array();
     $defaults = array('x' => 0, 'y' => 0, 'width' => 50, 'height' => 50, 'changed' => 0);
     if ($fid) {
         $file_info = imagefield_crop_get_file_info($fid);
         if ($file_info) {
             $defaults = array_merge($defaults, $file_info);
         }
     }
     foreach ($defaults as $name => $default) {
         $element[$name] = array('#type' => 'hidden', '#title' => $name, '#attributes' => array('class' => array('edit-image-crop-' . $name)), '#default_value' => $default);
     }
     return $element;
 }