protected function parseCropParameter($crop)
 {
     if ($crop) {
         /* @var ResourceImageDOInterface $resource */
         $resource = $this->resourceDO;
         $crop = explode('x', $crop);
         if (count($crop) != 4) {
             throw new WrongRequestException('Crop parameter has to consist of four parts, concatenated by "x" char.');
         }
         $cropObject = new CropImageDO();
         $cropObject->setX((int) $crop[0]);
         $cropObject->setY((int) $crop[1]);
         $cropObject->setWidth((int) $crop[2]);
         $cropObject->setHeight((int) $crop[3]);
         if (!$resource->getWidth() || !$cropObject->getHeight()) {
             throw new WrongRequestException('You should send the size=[X]x[Y] parameter together with the crop parameter');
         }
         if ($cropObject->getX() < 0 || $cropObject->getY() < 0 || $cropObject->getWidth() < 1 || $cropObject->getHeight() < 1) {
             throw new WrongRequestException('Crop parameters can not be less than zero');
         }
         $resource->setCrop($cropObject);
     }
 }
Example #2
0
 protected function appendCropToDO(ResourceDO $image)
 {
     $crop = new CropImageDO();
     $crop->setX(10);
     $crop->setY(10);
     $crop->setWidth(50);
     $crop->setHeight(50);
     $image->setCrop($crop);
     return $image;
 }