/** * @param Picture $picture * @param array $data */ protected function postSave(Picture $picture, array $data) { if (isset($data['meta']) && isset($data['meta']['filename'])) { $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary'); $file = new File($module->getUploadPath()->append($data['meta']['filename'])); $slugifier = new Slugify(); $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension()); $filepath = $module->getPicturesPath($picture->getSkill())->append($filename); $file->move($filepath); // create thumb folder $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs'); $dir = new Directory($thumbspath); if (!$dir->exists()) { $dir->make(); } // create thumb $imagine = new Imagine(); $image = $imagine->open($filepath->toString()); $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight()); $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE; $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE; $size = new Box($width, $height); $thumbpath = $thumbspath->append($filename); $image->thumbnail($size)->save($thumbpath->toString()); // save to picture $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename); $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename); $picture->save(); } // activity $user = $this->getServiceContainer()->getAuthManager()->getUser(); $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill())); }