From 08cb0c4957e891ad38a17f4d7a67d07697f33900 Mon Sep 17 00:00:00 2001 From: ramol Date: Fri, 18 Jan 2013 15:57:18 -0800 Subject: [PATCH 1/4] Create LICENSE --- LICENSE | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..90f1dfe --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2004-2013 Bulat Shakirzyanov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From 07c89d9f097426f7eb3283ab912c733cb86bedb8 Mon Sep 17 00:00:00 2001 From: "Phil. A" Date: Mon, 29 Apr 2013 21:02:42 +0200 Subject: [PATCH 2/4] Adding support for assetic --- Assetic/Filter/ImagineFilter.php | 88 +++++++++++++++++++ AvalancheImagineBundle.php | 2 + .../Compiler/AsseticCompilerPass.php | 28 ++++++ Resources/config/imagine.xml | 12 ++- 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 Assetic/Filter/ImagineFilter.php create mode 100644 DependencyInjection/Compiler/AsseticCompilerPass.php diff --git a/Assetic/Filter/ImagineFilter.php b/Assetic/Filter/ImagineFilter.php new file mode 100644 index 0000000..de3d588 --- /dev/null +++ b/Assetic/Filter/ImagineFilter.php @@ -0,0 +1,88 @@ +imagine = $imagine; + $this->filterManager = $filterManager; + $this->imagineFilter = $imagineFilter; + } + + /** + * Not in use + * + * @param AssetInterface $asset The asset + * + * @return void + */ + public function filterLoad(AssetInterface $asset) + { + } + + /** + * Main logic is located here. + * We parse the css here and create for all matching images a seperate asset + * + * @param AssetInterface $asset The asset + * + * @return void + */ + public function filterDump(AssetInterface $asset) + { + ob_start(); + try { + $format = $this->filterManager->getOption($this->imagineFilter, "format", "png"); + + $this->filterManager->getFilter($this->imagineFilter) + ->apply($this->imagine->load($asset->getContent())) + ->show($format); + + $asset->setContent(ob_get_clean()); + ob_end_clean(); + } catch (\Exception $e) { + ob_end_clean(); + throw $e; + } + } +} diff --git a/AvalancheImagineBundle.php b/AvalancheImagineBundle.php index 828ca31..bbe4694 100644 --- a/AvalancheImagineBundle.php +++ b/AvalancheImagineBundle.php @@ -3,6 +3,7 @@ namespace Avalanche\Bundle\ImagineBundle; use Avalanche\Bundle\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass; +use Avalanche\Bundle\ImagineBundle\DependencyInjection\Compiler\AsseticCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -16,5 +17,6 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new LoadersCompilerPass()); + $container->addCompilerPass(new AsseticCompilerPass()); } } diff --git a/DependencyInjection/Compiler/AsseticCompilerPass.php b/DependencyInjection/Compiler/AsseticCompilerPass.php new file mode 100644 index 0000000..8476daf --- /dev/null +++ b/DependencyInjection/Compiler/AsseticCompilerPass.php @@ -0,0 +1,28 @@ +hasDefinition('assetic.filter_manager')) { + return; + } + + $filters = $container->getParameter('imagine.filters'); + $asseticFilterManagerDef = $container->getDefinition('assetic.filter_manager'); + foreach($filters as $name => $options) { + $filterName = 'imagine_' . $name; + $filterClass = new DefinitionDecorator('imagine.assetic.filter'); + $filterClass->replaceArgument(2, $name); + $container->setDefinition('imagine.assetic.filter.' . $filterName, $filterClass); + $asseticFilterManagerDef->addMethodCall('set', array($filterName, new Reference('imagine.assetic.filter.' . $filterName))); + } + } +} diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml index 88607e1..208b77b 100644 --- a/Resources/config/imagine.xml +++ b/Resources/config/imagine.xml @@ -12,6 +12,9 @@ media/cache + + Avalanche\Bundle\ImagineBundle\Assetic\Filter\ImagineFilter + Avalanche\Bundle\ImagineBundle\Imagine\Filter\FilterManager @@ -52,7 +55,14 @@ - + + + + + + + + From b1a473da613a7e4886c42809f2f0738f5f0d7c3e Mon Sep 17 00:00:00 2001 From: "Phil. A" Date: Mon, 29 Apr 2013 22:57:25 +0200 Subject: [PATCH 3/4] Notice error fix --- Assetic/Filter/ImagineFilter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Assetic/Filter/ImagineFilter.php b/Assetic/Filter/ImagineFilter.php index de3d588..03e7d4e 100644 --- a/Assetic/Filter/ImagineFilter.php +++ b/Assetic/Filter/ImagineFilter.php @@ -79,9 +79,8 @@ public function filterDump(AssetInterface $asset) ->show($format); $asset->setContent(ob_get_clean()); - ob_end_clean(); } catch (\Exception $e) { - ob_end_clean(); + @ob_end_clean(); throw $e; } } From 535b345df8d6d801a8fbe52e2e6219300fff7c96 Mon Sep 17 00:00:00 2001 From: "Phil. A" Date: Sat, 4 May 2013 14:13:09 +0200 Subject: [PATCH 4/4] Making assetic support optional on a per filter basis, Added readme --- .../Compiler/AsseticCompilerPass.php | 12 +++++++----- README.md | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/DependencyInjection/Compiler/AsseticCompilerPass.php b/DependencyInjection/Compiler/AsseticCompilerPass.php index 8476daf..a031323 100644 --- a/DependencyInjection/Compiler/AsseticCompilerPass.php +++ b/DependencyInjection/Compiler/AsseticCompilerPass.php @@ -18,11 +18,13 @@ public function process(ContainerBuilder $container) $filters = $container->getParameter('imagine.filters'); $asseticFilterManagerDef = $container->getDefinition('assetic.filter_manager'); foreach($filters as $name => $options) { - $filterName = 'imagine_' . $name; - $filterClass = new DefinitionDecorator('imagine.assetic.filter'); - $filterClass->replaceArgument(2, $name); - $container->setDefinition('imagine.assetic.filter.' . $filterName, $filterClass); - $asseticFilterManagerDef->addMethodCall('set', array($filterName, new Reference('imagine.assetic.filter.' . $filterName))); + if (isset($options['options']) && isset($options['options']['assetic']) && ((bool) $options['options']['assetic'] === true )) { + $filterName = 'imagine_' . $name; + $filterClass = new DefinitionDecorator('imagine.assetic.filter'); + $filterClass->replaceArgument(2, $name); + $container->setDefinition('imagine.assetic.filter.' . $filterName, $filterClass); + $asseticFilterManagerDef->addMethodCall('set', array($filterName, new Reference('imagine.assetic.filter.' . $filterName))); + } } } } diff --git a/README.md b/README.md index 9137787..6262adf 100644 --- a/README.md +++ b/README.md @@ -369,4 +369,21 @@ $avalancheService = $this->get('imagine.cache.path.resolver'); Then, call the getBrowserPath and pass the original image webpath and the filter you want to use ```php $cachedImage = $avalancheService->getBrowserPath($object->getWebPath(), 'my_thumb'); -``` \ No newline at end of file +``` + +## Using in combination with assetic + +If you want to render static images with assetic, but want to leverage the image manipulation features +of imagine you can enable on a per filter basis assetic support. + +``` yaml +filters: + filtername: + options: { assetic: true } +``` + +If you enable assetic for a filter the filter will be available as an assetic filter with the imagine filters name, +prefixed by "imagine_" as in our example "imagine_filtername". + +Assetic has some name restriction this restriction apply here too, which means, the filtername +can only contain A-Z, 0-9 and underscores. This affects only filters with enabled assetic support. \ No newline at end of file