public function testUpdate_logo() { $pathfile = new \SplFileInfo(__DIR__ . '/../files/logocoll.gif'); self::$object->update_logo($pathfile); $this->assertEquals(file_get_contents($pathfile->getPathname()), self::$object->get_binary_minilogos()); }
public function write_collection_pic(Alchemyst $alchemyst, Filesystem $filesystem, collection $collection, SymfoFile $pathfile = null, $pic_type) { $filename = null; if (!is_null($pathfile)) { if (!in_array(mb_strtolower($pathfile->getMimeType()), ['image/gif', 'image/png', 'image/jpeg', 'image/jpg', 'image/pjpeg'])) { throw new \InvalidArgumentException('Invalid file format'); } $filename = $pathfile->getPathname(); if ($pic_type === collection::PIC_LOGO) { //resize collection logo $imageSpec = new ImageSpecification(); $media = $this->app['mediavorus']->guess($filename); if ($media->getWidth() > 120 || $media->getHeight() > 24) { $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); $imageSpec->setDimensions(120, 24); } $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg'; try { $alchemyst->turninto($pathfile->getPathname(), $tmp, $imageSpec); $filename = $tmp; } catch (\MediaAlchemyst\Exception $e) { } } elseif ($pic_type === collection::PIC_PRESENTATION) { //resize collection logo $imageSpec = new ImageSpecification(); $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); $imageSpec->setDimensions(650, 200); $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg'; try { $alchemyst->turninto($pathfile->getPathname(), $tmp, $imageSpec); $filename = $tmp; } catch (\MediaAlchemyst\Exception $e) { } } } switch ($pic_type) { case collection::PIC_WM: $collection->reset_watermark(); break; case collection::PIC_LOGO: case collection::PIC_PRESENTATION: break; case collection::PIC_STAMP: $collection->reset_stamp(); break; default: throw new \InvalidArgumentException('unknown pic_type'); break; } if ($pic_type == collection::PIC_LOGO) { $collection->update_logo($pathfile); } $file = $this->app['root.path'] . '/config/' . $pic_type . '/' . $collection->get_base_id(); $custom_path = $this->app['root.path'] . '/www/custom/' . $pic_type . '/' . $collection->get_base_id(); foreach ([$file, $custom_path] as $target) { if (is_file($target)) { $filesystem->remove($target); } if (null === $target || null === $filename) { continue; } $filesystem->mkdir(dirname($target), 0750); $filesystem->copy($filename, $target, true); $filesystem->chmod($target, 0760); } return $this; }