Example #1
0
 static function Parse($input)
 {
     $self = new static($input);
     return $self->getResult();
 }
 /**
  * Crop the document
  *
  * $backgroundColor can be set transparent (but script could be long to execute)
  * $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
  *
  * @param string $unit
  * @param float $width
  * @param float $height
  * @param float $positionX
  * @param float $positionY
  * @param string $position
  * @param string $backgroundColor
  */
 public function crop($unit = "pixel", $width = 0, $height = 0, $positionX = 0, $positionY = 0, $position = "LT", $backgroundColor = "ffffff")
 {
     if ($unit == "pourcent") {
         $width = round($width / 100 * $this->width);
         $height = round($height / 100 * $this->height);
         $positionX = round($positionX / 100 * $this->width);
         $positionY = round($positionY / 100 * $this->height);
     }
     if ($width != $this->width || $positionX == 0 || ($height != $this->height || $positionY == 0)) {
         $layerTmp = new static(array('width' => $width, 'height' => $height, 'backgroundColor' => $backgroundColor));
         $layerClone = new static(array('width' => $this->width, 'height' => $this->height));
         imagedestroy($layerClone->image);
         $layerClone->image = $this->image;
         $layerTmp->addLayer(1, $layerClone, -$positionX, -$positionY, $position);
         $newPos = $layerTmp->getLayerPositions();
         $layerNewPosX = $newPos[1]['x'];
         $layerNewPosY = $newPos[1]['y'];
         // update the layer
         $this->width = $layerTmp->getWidth();
         $this->height = $layerTmp->getHeight();
         $this->image = $layerTmp->getResult();
         unset($layerTmp);
         unset($layerClone);
         $this->updateLayerPositionsAfterCropping($layerNewPosX, $layerNewPosY);
     }
 }
Example #3
0
 /**
  * [[Description]]
  * @param  [[Type]] $value [[Description]]
  * @param  [[Type]] $rules [[Description]]
  * @return [[Type]] [[Description]]
  */
 public static function validateValue($value, $rules)
 {
     $tmp = new static(array('elem' => $value));
     $tmp->addSet('elem', $rules);
     if ($tmp->isValid()) {
         $value = $tmp->getResult();
         return new ValidationResult(true, $value['elem']);
     }
     return new ValidationResult(false, null);
 }