Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 8c3049937ba5848e55d3949ead12d93d4d9d3a93 1 parent 2ab28a2
@Alkpone Alkpone authored
View
6 Controller/ImagineController.php
@@ -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();
View
10 Imagine/Filter/FilterManager.php
@@ -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
13 README.md
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.