/** * Get a photo from the oC and crops it with the suplied geometry. * @NoAdminRequired * @NoCSRFRequired */ public function cropPhoto() { $params = $this->request->urlParams; $x = $this->params('x', 0); $y = $this->params('y', 0); $w = $this->params('w', -1); $h = $this->params('h', -1); $tmpkey = $params['key']; $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']); $contact = $addressBook->getChild($params['contactId']); $response = new JSONResponse(); $tmpPhoto = new TemporaryPhoto($this->cache, $tmpkey); $image = $tmpPhoto->getPhoto(); if (!$image || !$image->valid()) { return $response->bailOut(App::$l10n->t('Error loading image from cache')); } $w = $w !== -1 ? $w : $image->width(); $h = $h !== -1 ? $h : $image->height(); $image->crop($x, $y, $w, $h); if (!$contact->setPhoto($image)) { $tmpPhoto->remove($tmpkey); return $response->bailOut(App::$l10n->t('Error getting PHOTO property.')); } if (!$contact->save()) { return $response->bailOut(App::$l10n->t('Error saving contact.')); } $thumbnail = Properties::cacheThumbnail($params['backend'], $params['addressBookId'], $params['contactId'], $image, $contact); $response->setData(array('status' => 'success', 'data' => array('id' => $params['contactId'], 'thumbnail' => $thumbnail))); $tmpPhoto->remove($tmpkey); return $response; }