You are here

public function ImageCrop::writeCropreadyImage in Image javascript crop 7

Write the file to crop, and apply all effects, untill the imagecrop effectso cropping can be done.

File

includes/imagecrop.class.inc, line 516
Imagecrop class to handle the javascript imagecrop.

Class

ImageCrop
@file Imagecrop class to handle the javascript imagecrop.

Code

public function writeCropreadyImage() {
  $unset = FALSE;
  $smartcrop = FALSE;
  $style = $this->imageStyle;
  foreach ($this->imageStyle['effects'] as $key => $effect) {
    if ($effect['name'] == 'smartcrop_crop') {
      $smartcrop = $effect;

      //  $unset = TRUE;
    }
    if ($effect['name'] == 'imagecrop_javascript') {
      $unset = TRUE;
    }
    if ($unset) {
      unset($style['effects'][$key]);
    }
  }

  /*if ($smartcrop) {
      $image = image_load($this->file->uri);
      $coordinates = _smartcrop_get_coordinates($image, $this->width, $this->height);
      if (!$this->hasSettings) {
        $this->xoffset = $coordinates['dst_x'];
        $this->yoffset = $coordinates['dst_y'];
      }
    }*/

  // Save a first time, after the effects are done, for knowing the resulted width / height
  image_style_create_derivative($style, $this->file->uri, $this->cropDestination);

  // Set imageWidth and height after effects are done.
  $size = getimagesize($this->cropDestination);
  $this->imageWidth = $this->originalImageWidth = $size[0];
  $this->imageHeight = $this->originalImageHeight = $size[1];
  $changed = FALSE;
  if ($this->scale !== 'original') {
    $style['effects'][] = array(
      'effect callback' => 'image_scale_effect',
      'data' => array(
        'width' => $this->scale,
      ),
    );
    $changed = TRUE;
  }
  if ($this->rotation > 0) {
    $style['effects'][] = array(
      'effect callback' => 'image_rotate_effect',
      'data' => array(
        'degrees' => $this->rotation,
      ),
    );
    $changed = TRUE;
  }

  // Extra changes need to be done, save second time.
  if ($changed) {
    image_style_create_derivative($style, $this->file->uri, $this->cropDestination);
  }
}