public function setPhoto(\GO\Base\Fs\File $file) { if ($this->isNew) { throw new \Exception("Cannot save a photo on a new contact that is not yet saved."); } $this->getPhotoFile()->delete(); $photoPath = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'addressbook/photos/' . $this->addressbook_id . '/'); $photoPath->create(); // if(strtolower($file->extension())!='jpg'){ $filename = $photoPath->path() . '/com_' . $this->id . '.jpg'; $img = new \GO\Base\Util\Image(); if (!$img->load($file->path())) { throw new \Exception(\GO::t('imageNotSupported', 'addressbook')); } $aspectRatio = $img->getHeight() > $img->getWidth() ? $img->getHeight() / $img->getWidth() : $img->getWidth() / $img->getHeight(); //resize it to small image so we don't get in trouble with sync clients if ($img->getHeight() > $img->getWidth()) { $img->fitBox(320 / $aspectRatio, 320); } else { $img->fitBox(320, 320 / $aspectRatio); } if (!$img->save($filename, IMAGETYPE_JPEG)) { throw new \Exception("Could not save photo!"); } $file = new \GO\Base\Fs\File($filename); // }else // { // $file->move($photoPath, $this->id.'.'.strtolower($file->extension())); // } $this->photo = $file->stripFileStoragePath(); }