Permalink
Browse files

Allow to specify the format and the quality of the image saved

  • Loading branch information...
AlbanSeurat committed Apr 20, 2012
1 parent 2ab28a2 commit 8c3049937ba5848e55d3949ead12d93d4d9d3a93
Showing with 26 additions and 3 deletions.
  1. +3 −3 Controller/ImagineController.php
  2. +10 −0 Imagine/Filter/FilterManager.php
  3. +13 −0 README.md
@@ -127,12 +127,12 @@ public function filter($path, $filter)
// TODO: get rid of hard-coded quality and format
$this->filterManager->get($filter)
->apply($this->imagine->open($sourcePath))
- ->save($realPath, array('quality' => 100))
- ->show('png');
+ ->save($realPath, array('quality' => $this->filterManager->getOption($filter, "quality", 100)))
+ ->show($this->filterManager->getOption($filter, "format", "png"));
// TODO: add more media headers
return new Response(ob_get_clean(), 201, array(
- 'content-type' => 'image/png',
+ 'content-type' => 'image/' . $this->filterManager->getOption($filter, "format", "png"),
));
} catch (\Exception $e) {
ob_end_clean();
@@ -56,4 +56,14 @@ public function get($filter)
return $this->loaders[$options['type']]->load($options['options']);
}
+
+ public function getOption($filter, $name, $default = null) {
+
+ $options = $this->filters[$filter];
+
+ if($options && isset($options["options"]) && isset($options["options"][$name]))
+ return $options["options"][$name];
+
+ return $default;
+ }
}
View
@@ -127,6 +127,19 @@ avalanche_imagine:
options: { size: [120, 90], mode: outbound }
```
+You can also change the quality and the format you want to use to save our image :
+
+
+``` yaml
+# app/config/config.yml
+
+avalanche_imagine:
+ filters:
+ my_thumb:
+ type: thumbnail
+ options: { size: [120, 90], mode: outbound, quality: 100, format: png }
+```
+
You've now defined a filter called `my_thumb` that performs a thumbnail transformation.
We'll learn more about available transformations later, but for now, this
new filter can be used immediately in a template:

0 comments on commit 8c30499

Please sign in to comment.