Пример #1
0
 public function write_databox_pic(Alchemyst $alchemyst, Filesystem $filesystem, databox $databox, SymfoFile $pathfile = null, $pic_type)
 {
     $filename = null;
     if (!is_null($pathfile)) {
         if (!in_array(mb_strtolower($pathfile->getMimeType()), ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/gif'])) {
             throw new \InvalidArgumentException('Invalid file format');
         }
     }
     if (!in_array($pic_type, [databox::PIC_PDF])) {
         throw new \InvalidArgumentException('unknown pic_type');
     }
     if ($pathfile) {
         $filename = $pathfile->getPathname();
         $imageSpec = new ImageSpecification();
         $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO);
         $imageSpec->setDimensions(120, 35);
         $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg';
         try {
             $alchemyst->turninto($pathfile->getPathname(), $tmp, $imageSpec);
             $filename = $tmp;
         } catch (\MediaAlchemyst\Exception $e) {
         }
     }
     $file = $this->app['root.path'] . '/config/minilogos/' . $pic_type . '_' . $databox->get_sbas_id() . '.jpg';
     $custom_path = $this->app['root.path'] . '/www/custom/minilogos/' . $pic_type . '_' . $databox->get_sbas_id() . '.jpg';
     foreach ([$file, $custom_path] as $target) {
         if (is_file($target)) {
             $filesystem->remove($target);
         }
         if (is_null($filename)) {
             continue;
         }
         $filesystem->mkdir(dirname($target));
         $filesystem->copy($filename, $target);
         $filesystem->chmod($target, 0760);
     }
     $databox->delete_data_from_cache('printLogo');
     return $this;
 }
 /**
  * @param File $file
  * @param $imageSpec
  * @return string
  * @throws \MediaAlchemyst\Exception\FileNotFoundException
  */
 protected function resizeMediaFile(File $file, $imageSpec)
 {
     $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg';
     $this->alchemyst->turninto($file->getPathname(), $tmp, $imageSpec);
     return $tmp;
 }